C# 和 VB.NET 之间最重要的功能区别是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 17:39:30  来源:igfitidea点击:

What are the most important functional differences between C# and VB.NET?

提问by Larsenal

Certainly there's the difference in general syntax, but what other critical distinctions exist? There are somedifferences, right?

当然,在一般语法上存在差异,但还有哪些其他重要的区别?有一些区别,对吧?

采纳答案by Luke

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, too
  • C# 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#.
  • C# 有匿名方法VB 现在也有这些
  • C# 有 yield 关键字(迭代器块)VB11 添加了这个
  • VB 支持隐式后期绑定(C# 现在通过 dynamic 关键字具有显式后期绑定)
  • VB 支持 XML 文字
  • VB 不区分大小写
  • 更多用于 VB 的现成代码片段
  • 更多现成的 C# 重构工具Visual Studio 2015 现在为 VB 和 C# 提供相同的重构工具。

In general the things MS focuses on for each vary, because the two languages are targeted at very different audiences. This blog posthas 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.

一般而言,MS 关注的内容各不相同,因为这两种语言针对的受众非常不同。这篇博文很好地总结了目标受众。确定您的受众群体可能是一个好主意,因为这将决定您将从 Microsoft 获得哪种工具。

回答by Rob Allen

This topic has had a lot of face time since .Net 2.0 was released. See this Wikipediaarticle for a readable summary.

自从 .Net 2.0 发布以来,这个话题就已经出现了很多次。有关可读摘要,请参阅此Wikipedia文章。

回答by Tom Grochowicz

Thisis a very comprehensive reference.

是一个非常全面的参考。

回答by csmba

Since I assume you can google, I don't think a link to more sites is what you are looking for.

由于我假设您可以 google,因此我认为您要查找的不是指向更多网站的链接。

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.

我的回答:根据开发人员的历史选择。C# 更像 JAVA,可能更像 C++。VB.NET 对 VB 程序员来说更容易,但我想这不再是一个真正的问题,因为没有来自旧 VB 的新 .NET 程序员。

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.

我的观点是 VB 比 C# 更有效率,它似乎在生产力工具(例如 intelisense)方面总是领先,我会向提出要求的人推荐 vb 而不是 c#。当然,知道自己更喜欢 c# 的人不会问,而 c# 可能是他的正确选择。

回答by Keith

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#.

除了语法没有那么多了。它们都编译为完全相同的 IL,因此您可以将某些内容编译为 VB 并将其反映到 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.

大多数明显的差异是语法糖。例如,VB 似乎支持动态类型,但实际上它们和 C# 一样是静态的——VB 编译器会计算出来。

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.

Visual Studio 在 VB 中的行为与在 C# 中的行为不同——它隐藏了许多功能,但添加了后台编译(非常适合小型项目,大型项目的资源占用)和更好的代码片段支持。

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 handleskeyword - and that's of debatable benefit.

随着 C#3 中越来越多的编译器“魔术”,VB.Net 真的落后了。VB 现在唯一一个 C# 没有的东西是handles关键字——这是有争议的好处。

@Tom - that really useful, but a little out of date - VB.Net now supports XML docs too with '''

@Tom - 这真的很有用,但有点过时 - VB.Net 现在也支持 XML 文档 '''

@Luke - VB.Net still doesn't have anon-methods, but does now support lambdas.

@Luke - VB.Net 仍然没有匿名方法,但现在支持 lambdas。

回答by Seibar

This may be considered syntax, but VB.NET is case insensitive while C# is case sensitive.

这可以被认为是语法,但VB.NET是案件敏感,而C#是区分大小写

回答by DevelopingChris

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.

当它到达IL时,它只是位。不区分大小写只是预编译器传递。但普遍的共识是,vb 更冗长。如果您可以编写 c#,为什么不节省您的眼睛和双手并编写更少量的代码来做同样的事情。

回答by DevelopingChris

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.

尽管 C#3 上的语法糖确实推动了这一标准,但我必须说 VB.Net 中的一些 Linq to XML 内容看起来非常好,并且使处理复杂的、深度嵌套的 XML 更容易接受。只是一点点。

回答by Vaibhav

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/

一个明显的区别在于它们处理扩展方法的方式(Vb.Net 实际上允许 C# 不允许的东西 - 传递扩展方法被定义为 ref 的类型):http: //blog.gadodia.net/extension- vbnet-and-c/ 中的方法

回答by Vaibhav

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/

一个明显的区别在于它们处理扩展方法的方式(Vb.Net 实际上允许 C# 不允许的东西 - 传递扩展方法被定义为 ref 的类型):http: //blog.gadodia.net/extension- vbnet-and-c/ 中的方法