分享
 
 
 

选择 VB.NET 还是 C#?

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

选择 VB.NET 还是 C#?

选择 VB.NET 还是 C#? 选择 VB.NET 还是 C#?

面向对象的编程方法在.NET的世界里已经是大势所趋,你选择VB.NET还是C#??

With VB.NET, Microsoft has given Visual Basic programmers all the things we've been asking for over the years, namely a true object-oriented programming language. You may be hearing the buzz that VB.NET is so different you won't even recognize it. Sure, they had to remove some minor things in the language, and change some of the objects, properties, and methods, but this shouldn't be a big deal to most Visual Basic programmers. In fact, I think after you start to use it regularly, you'll find it's simpler and more intuitive than previous versions of Visual Basic. Because there will be a learning curve with Visual Basic.NET, you might be curious about C# and wondering if you should give up Visual Basic altogether.

If you are currently a Visual Basic programmer, and especially if you have been for years, you won't need to switch to another language like C# or Delphi. You'll find the core language of Visual Basic is still the same, although there are some minor differences. The majority of the changes are in the objects, properties, and methods you use in VB.NET. You have to learn these new things no matter which .NET language you choose to use.

Now, if you've been using BASIC since the old DOS days, then you're in for a shock, as they have removed GoSub, While/Wend, Let a=b, and a host of other obsolete commands. But Microsoft has been warning you not to use these unstructured statements anyway.

Advantages of VB.NET

VB.NET has features that C# doesn't. For example, the IsDBNull() function is in VB.NET, but not in C#. VB.NET has exponentiation and can re-allocate arrays using Redim; these aren't available in C#. C# is case-sensitive for keywords and variables. Most Visual Basic programmers aren't used to this, and this can cause lost time unless you're really consistent in your typing. Personally, I like Visual Basic's use of If. . .End If and Do. . .Loop as opposed to C#'s use of curly braces. I find it hard to keep track of these braces. Select Case statements are easier and more compact than in C#. In C#, you have to use the break statement all the time to break out of the select structure. In Visual Basic, you can use Case 1 to 50: In C#, you have to code 50 individual case statements for this.

When you're using the OOP features of Visual Basic, you'll find keywords words like Inherits, MustInherit, NotInheritable, Overridable, and so on. In C#, these same features involve more cryptic words and syntax. For example, to inherit a base class in VB.NET, you would write something like this:

Public Class Person

...

End Class

Public Class Employee

Inherits Person

...

End Class

Here's the same code in C#:

public class Person

{

public Person() {

...

}

}

public class Employee : Person

{

public Employee() {

...

}

}

If you don't look closely, you may miss the fact that the Employee class in the C# version is inherited from the Person class (denoted by the Employee : Person syntax).

How bad will the upgrade process be?

The migration from Visual Basic 6.0 to VB.NET won't be without challenge, but there are some things you can do now to prepare. First, use classes, COM components, and n-tier development techniques. If you use these programming constructs, you'll have the easiest migration path since these convert to .NET. There are some programming styles that won't migrate so easily -- for example, non-zero-based arrays, implicit variables (not using Option Explicit), and Jet or RDO. You'll have to do some significant rewriting to port these types of applications.

There is nothing wrong with keeping your existing applications in Visual Basic 6.0 and just doing new development in VB.NET. The two will co-exist on one machine just fine. In fact, this will probably be a common approach.

Introducing C#

Microsoft had a couple of goals in mind when they created C#. First, they needed an alternative to Java. With their constant court battles over this language, and most people viewing Java as a Sun product, Microsoft needed their own language that was similar to Java, but distinctly their own. In addition, Microsoft wanted a new, clean language that didn't have any legacy code that users still needed to maintain. The result is a clean language, without a lot of baggage.

The people who will most likely use the C# language will be Java, C, and C++ developers. These programmers will already be familiar with the language constructs and the case sensitivity. They'll also have the learning curve of the .NET classes to deal with, so they don't have much of an advantage over Visual Basic developers.

Advantages of C#

I am admittedly a Visual Basic proponent, but C# does have some advantages. For example, the ability to have multi-line comments without having to repeat the comment character is pretty slick. C# can also do pre- and post-incrementing and decrementing, for example:

intValue--

intValue-

The first line in the above code increments the variable intValue by one. The second line decrements the variable by one. This is a nice shorthand compared to the more lengthy Visual Basic version of intValue += 1.

Another benefit of C# is that there are currently more sample programs in the beta version than there are samples in VB.NET. This will likely change in a future release.

Although not often used for business applications, C# lets you have pointers. While pointers can lead to many problems, there may be times when you need them. In this instance, C# has a slight advantage over Visual Basic. However, in my programming, I rarely need pointers.

C# has the ability to use the Unsigned data types defined in the .NET runtime. Again, the need for this in a business application isn't common, but it is an area where C# has more access to the .NET runtime engine than VB.NET.

The migration road

The road from Visual Basic 6.0 to VB.NET won't be easy, but I think it will be well worth the investment in time for you to learn this new language. In the meantime, I recommend you start learning OOP-style programming. You're definitely going to need it for programming in the .NET world. Whichever language you choose, you'll find the .NET platform is excellent for creating desktop, Internet, intranet, and distributed applications.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有