Certainly there's the difference in general syntax, but what other critical distinctions exist? There are some differences, right?
问题:
回答1:
The linked comparisons are very thorough, but as far as the main differences I would note the following:
C# has anonymous methodsVB has these now, tooC# has the yield keyword (iterator blocks)VB11 added this- VB supports implicit late binding (C# has explicit late binding now via the dynamic keyword)
- VB supports XML literals
- VB is case insensitive
- More out-of-the-box code snippets for VB
More out-of-the-box refactoring tools for C#Visual Studio 2015 now provides the same refactoring tools for both VB and C#.
In general the things MS focuses on for each vary, because the two languages are targeted at very different audiences. This blog post has a good summary of the target audiences. It is probably a good idea to determine which audience you are in, because it will determine what kind of tools you'll get from Microsoft.
回答2:
This topic has had a lot of face time since .Net 2.0 was released. See this Wikipedia article for a readable summary.
回答3:
This may be considered syntax, but VB.NET is case insensitive while C# is case sensitive.
回答4:
This is a very comprehensive reference.
回答5:
Since I assume you can google, I don't think a link to more sites is what you are looking for.
My answer: Choose base on the history of your developers. C# is more JAVA like, and probably C++ like. VB.NET was easier for VB programmers, but I guess that is no really an issue anymore sine there are no new .NET programmers coming from old VB.
My opinion is that VB is more productive then C#, it seems it is always ahead in terms of productivity tools (such as intelisense), and I would recommend vb over c# to someone that asks. Of course, someone that knows he prefers c# won't ask, and c# is probably the right choice for him.
回答6:
Although the syntax sugar on C#3 has really pushed the bar forward, I must say some of the Linq to XML stuff in VB.Net seems quite nice and makes handling complex, deeply nested XML a little bit more tolerable. Just a little bit.
回答7:
One glaring difference is in how they handle extension methods (Vb.Net actually allows something that C# doesn't - passing the type on which the extension method is being defined as ref): http://blog.gadodia.net/extension-methods-in-vbnet-and-c/
回答8:
Apart from syntax not that much any more. They both compile to exactly the same IL, so you can compile something as VB and reflect it into C#.
Most of the apparent differences are syntactic sugar. For instance VB appears to support dynamic types, but really they're just as static as C#'s - the VB compiler figures them out.
Visual Studio behaves differently with VB than with C# - it hides lots of functionality but adds background compiling (great for small projects, resource hogging for large ones) and better snippet support.
With more and more compiler 'magic' in C#3 VB.Net has really fallen behind. The only thing VB now has that C# doesn't is the handles
keyword - and that's of debatable benefit.
@Tom - that really useful, but a little out of date - VB.Net now supports XML docs too with '''
@Luke - VB.Net still doesn't have anon-methods, but does now support lambdas.
回答9:
The biggest difference in my opinion is the ability to write unsafe code in C#.
回答10:
Although VB.NET supports try...catch type exception handling, it still has something similar to VB6's ON ERROR. ON ERROR can be seriously abused, and in the vast majority of cases, try...catch is far better; but ON ERROR can be useful when handling COM time-out operations where the error can be trapped, decoded, and the final "try again" is a simple one line. You can do the same with try...catch but the code is a lot messier.
回答11:
This topic is briefly described at wikipedia and harding.
http://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Visual_Basic_.NET http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
Just go through and make your notes on that.
回答12:
When it gets to IL its all just bits. That case insensitivity is just a precompiler pass. But the general consensus is, vb is more verbose. If you can write c# why not save your eyes and hands and write the smaller amount of code to do the same thing.
回答13:
One glaring difference is in how they handle extension methods (Vb.Net actually allows something that C# doesn't - passing the type on which the extension method is being defined as ref): http://blog.gadodia.net/extension-methods-in-vbnet-and-c/
回答14:
Scott Hanselman recently wrote an interesting article contrasting var and Dim: Back to Basics: var != Dim
回答15:
Yes VB.NET fixed most of the VB6 problems and made it a proper OOP language - ie. Similar in abilities to C#. AlthougnI tend to prefer C#, I do find the old VB ON ERROR construct useful for handling COM interop timeouts. Something to use wisely though - ON ERROR is easily abused!!