same thing.
The difference between the functionality of VB .NET and C# is even smaller. If you create a new project in Visual Studio .NET, you see the exact same project types listed for each language. So, if the project types are the same, and the functionality differences between the languages are small, does it matter which you choose?
If the answer was no, this would be a short article. The fact is that the language you choose probably won’t hinge on the functionality in the language itself. Instead, your choice will hinge on some other criteria, which we’ll examine in a moment.
看一下细节的东西吧!
What about Speed?
速度的问题呢?
Unfortunately, it’s too early to tell about speed. According to Microsoft, the speed between the two languages will be the same. Much of your code actually will be calling classes in the CLR, so that will be the same regardless of the language used to call it. As for the speed of items such as loops and string concatenation, that will depend on the compiler.
Microsoft officials say VB .NET and C# will compile to the same IL, so the result will be the same speed. I must admit I’m skeptical, but there is no way to test this at this time. With .NET still in beta (.NET was not yet final when this article went to press. - Ed.), any speed tests most likely would bear little resemblance to the final product. For now, assume the speed will be very close, and don’t worry about it until .NET is a finished product.
看来速度还是差不多,播种之间。
What about Language Differences?
The differences in the languages are small, but they do exist. For example, C# allows you to have unsigned integers of various sizes, and VB .NET does not. It is important to note, however, that unsigned integers are not part of the Common Language Specification (CLS), a part of the .NET Framework that defines what language elements can be used to allow inheritance between languages. If cross-language inheritance is something you want to ensure, you need to stick to only CLS-compliant types for any exposed parameters and return values.
小细节:C#拥有无符号整数、VB.NET没有。但是无符号数不符合CLS规范,不利于跨语言继承。还是建议不要用无符号数。
VB .NET adds some of the C/C++ shortcuts, such as +=, -=, and others. Now, in VB .NET, x += 5 is the same as x = x + 5. However, VB .NET does not support the ++ or -- operators, which C/C++ programmers frequently use. C# supports all of these, of course. C# also supports the concept of operator overloading, in which a developer can overload operators such as +, - , and True. Operator overloading is admittedly not something most VB .NET developers will miss, but it is one of the differences between the two languages.
VB.NET增加了一些C++的特性,比如+=,-=.但是C#全面保留了原来C++的这姓特性,比如++ ,――,这些还不是很重要的。VB.NET不具有运算符重载,这倒是两个语言的一个小区别。
I won’t go into the differences in the actual syntax here, except for two items that are only relevant to VB developers thinking of making the switch to C#: case sensitivity and the equality operator. (See Eric Smith’s article There and Back Again for more on syntactical differences and how to move code from one language to another.) Don’t forget that VB and VB .NET are not case sensitive, while C# is. Also, the assignment operator in C# is the equal sign (=) but the equality operator is the double equal sign (==). These two differences are a major headache for VB developers trying to make the switch to C#.
Vb和VB.NET都是大小写不分的,C#是区别的。还有,两者是不是相等,C#还是两个等号。
To see some of the general language differences, check out the sample VB .NET code in FIGURE 1.
两个具体的例子:
Module Module1
Sub Main()
Dim x As Integer = 5
Console.WriteLine("The secret number is: " & x)
End Sub
End Module
FIGURE 1: Sample VB .NET code.
As you can see, VB .NET now allows you to initialize variable values at declaration. The next line uses the WriteLine method of the Console class. There is some simple string concatenation, and the string is printed to the console (or the DOS window or command window).
FIGURE 2 shows the same application written in C#. The variable declaration is cleaner, but the Console.WriteLine is almost identical. Notice the curly braces and semicolons in the C# program, which are familiar to C/C++ and Java developers.
using System;
namespace ConsoleApplication3
{
class Class1
{
static void Main(string[] args)
{
int x=5;
Console.WriteLine("The secret number is: " + x);
}
}
}
FIGURE 2: The same application as in FIGURE 1, but written上一页 [1] [2] [3] [4] 下一页 [VB.NET程序]GSM短信模块库函数,可以用VB,VC,调用简单实用 [C语言系列][C#防止反编译].NET 产品版权保护方案 (.NET源码加… [互联动态].NETFramework3.0新特性介绍与问答翻译 [Web开发]asp.net代码空格显示为……点号的原因及解决办法 [Web开发]asp.net调用压缩软件对文件进行压缩与解压缩的代码 [Web开发]详细介绍asp.net获取日期时间的各种格式的函数 [Web开发]如何将JS文件编译到ASP.NET项目里的DLL文件中 [Web开发]asp.net加密口令的最简单方法 [Web开发]目前asp.net开发主流工具软件介绍 [Web开发]asp.net中的反射介绍
|