| 導購 | 订阅 | 在线投稿
分享
 
 
 

選擇 VB.NET 還是 C#?

來源:互聯網  2006-12-17 09:47:45  評論

選擇 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.

選擇 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.
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有