VB 和 VB.NET 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4721871/
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
What is the difference between VB and VB.NET?
提问by user287745
What is the difference between VB and VB.NET?
VB 和 VB.NET 有什么区别?
Explanation with examples is preferred.
最好有例子说明。
采纳答案by Dan Puzey
If you're making a choice for a new project then the pertinent points are:
如果您要为新项目做出选择,那么相关要点是:
- VB6 is legacy (released 1998, the IDE is no longer supported, and the runtime only supported for the lifetime of Win8)
- VS2008 doesn't support VB6
- VB.NET is a modern language, supported in VS2008
- VB6是legacy(1998年发布,IDE不再支持,运行时只支持Win8的生命周期)
- VS2008 不支持 VB6
- VB.NET 是一种现代语言,VS2008 支持
I'd say there are very few reasons (if any!) to choose VB.OLD over VB.NET.
我想说选择 VB.OLD 而不是 VB.NET 的理由很少(如果有的话!)。
If you're "just interested" then the Wikipedia article on each language is quite informative, but in a nutshell they are quite different languages that have superficially similar syntax. VB had its own runtime, where VB.NET is one of many languages that use the more modern .NET Framework.
如果您“只是感兴趣”,那么关于每种语言的维基百科文章都非常有用,但简而言之,它们是完全不同的语言,它们具有表面上相似的语法。VB 有自己的运行时,其中 VB.NET 是使用更现代的 .NET Framework 的众多语言之一。
回答by Tim Schmelter
There are a lot of differences.
有很多不同之处。
- The greatest change in VB6 and VB.NET is of runtime environment. VB6 used the VB-Runtime while VB.NET uses the .Net Common Language Runtime (.Net CLR). The CLR is much better designed and implemented than VB-Runtime. The CLR uses better code translation through Just in Time compiler while VB-Runtime interprets the code. The CLR Garbage Collector is also more efficient than VB6 one as it may detect cyclic references too.
- VB6 was interpreter based language while VB.NET is a compiled language
- VB6 was not a type-safe language while VB.NET is a type safe language. There is no variant type in VB.NET and no magical type conversions happen in VB.NET
- VB6和VB.NET最大的变化是运行环境。VB6 使用 VB-Runtime,而 VB.NET 使用 .Net Common Language Runtime (.Net CLR)。CLR 的设计和实现比 VB-Runtime 好得多。CLR 通过即时编译器使用更好的代码转换,而 VB-Runtime 解释代码。CLR 垃圾收集器也比 VB6 更有效,因为它也可以检测循环引用。
- VB6 是基于解释器的语言,而 VB.NET 是编译语言
- VB6 不是类型安全语言,而 VB.NET 是类型安全语言。VB.NET 中没有变体类型,VB.NET 中没有发生神奇的类型转换
some other differences:
其他一些区别:
Inheritance
遗产
VB.Net supports inheritance by allowing you to define classes that serve as the basis for derived classes. Derived classes inherit and can extend on the properties and methods of the base class. They can also override inherited methods with new implementations of the base class. All classes created with VB.Net are inheritable by default. Because the forms you design are really classes, you can use inheritance to define new forms based on existing ones. For details, see Inheritance in Visual Basic.
VB.Net 通过允许您定义作为派生类基础的类来支持继承。派生类继承并可以扩展基类的属性和方法。它们还可以使用基类的新实现来覆盖继承的方法。默认情况下,所有用 VB.Net 创建的类都是可继承的。因为您设计的表单实际上是类,您可以使用继承来定义基于现有表单的新表单。有关详细信息,请参见Visual Basic 中的继承。
Exception Handling
异常处理
VB.Net supports structured exception handling, using an enhanced version of the Try...Catch...Finally syntax supported by other languages such as C++. Structured exception handling combines a modern control structure (similar to Select Case or While) with exceptions, protected blocks of code, and filters. Structured exception handling makes it easy to create and maintain programs with robust, comprehensive error handlers. For details, see Introduction to Exception Handling.
VB.Net 支持结构化异常处理,使用增强版本的 Try...Catch...Finally 语法,其他语言如 C++ 支持。结构化异常处理将现代控制结构(类似于 Select Case 或 While)与异常、受保护的代码块和过滤器相结合。结构化异常处理使创建和维护具有强大、全面的错误处理程序的程序变得容易。有关详细信息,请参阅异常处理简介。
Overloading
超载
Overloading is the ability to define properties, methods, procedures, or operators that have the same name but use different data types. You can use overloaded procedures to provide as many implementations as necessary to handle different kinds of data, while giving the appearance of a single, versatile procedure. For details, see Overloaded Properties and Methods.
重载是定义具有相同名称但使用不同数据类型的属性、方法、过程或运算符的能力。您可以使用重载过程提供尽可能多的实现来处理不同类型的数据,同时提供单一、通用过程的外观。有关详细信息,请参阅重载的属性和方法。
Overriding Properties and Methods
覆盖属性和方法
The Overrides keyword allows derived objects to override characteristics inherited from parent objects. Overridden members have the same arguments as the members inherited from the base class, but they have different implementations. A member's new implementation can call the original implementation in the parent class by preceding the member name with MyBase. For details, see Overriding Properties and Methods.
Overrides 关键字允许派生对象覆盖从父对象继承的特征。覆盖成员与从基类继承的成员具有相同的参数,但它们具有不同的实现。成员的新实现可以通过在成员名称前加上 MyBase 来调用父类中的原始实现。有关详细信息,请参阅覆盖属性和方法。
Constructors and Destructors
构造函数和析构函数
Constructors are procedures that control initialization of new instances of a class. Conversely, destructors are methods that free system resources when a class leaves scope or is set to Nothing. VB.Net supports constructors and destructors using the Sub New and Sub Finalize procedures. For details, see Object Lifetime: How Objects Are Created and Destroyed.
构造函数是控制类的新实例的初始化的过程。相反,析构函数是在类离开作用域或设置为 Nothing 时释放系统资源的方法。VB.Net 支持使用 Sub New 和 Sub Finalize 过程的构造函数和析构函数。有关详细信息,请参阅对象生命周期:如何创建和销毁对象。
Data Types
数据类型
VB.Net introduces three new data types. The Char data type is an unsigned 16-bit quantity used to store Unicode characters. It is equivalent to the .NET Framework System.Char data type. The Short data type, a signed 16-bit integer, was named Integer in earlier versions of Visual Basic. The Decimal data type is a 96-bit signed integer scaled by a variable power of 10. In earlier versions of Visual Basic, it was available only within a Variant. In addition, Visual Basic now supports unsigned integer data types (UShort, UInteger, and ULong), as well as the signed type SByte. For details, see Data Types in Visual Basic.
VB.Net 引入了三种新的数据类型。Char 数据类型是一个无符号的 16 位数量,用于存储 Unicode 字符。它等效于 .NET Framework System.Char 数据类型。Short 数据类型是一个有符号的 16 位整数,在 Visual Basic 的早期版本中被命名为 Integer。Decimal 数据类型是一个 96 位有符号整数,按 10 的可变幂进行缩放。在 Visual Basic 的早期版本中,它仅在 Variant 中可用。此外,Visual Basic 现在支持无符号整数数据类型(UShort、UInteger 和 ULong),以及有符号类型 SByte。有关详细信息,请参见Visual Basic 中的数据类型。
Interfaces
接口
Interfaces describe the properties and methods of classes, but unlike classes, interfaces do not provide implementations. Use the Interface statement to declare interfaces; use the Implements statement to write code that puts the items described in the interface into practice. For details, see Interfaces in Visual Basic.
接口描述类的属性和方法,但与类不同的是,接口不提供实现。使用Interface语句声明接口;使用Implements 语句编写代码,将接口中描述的项目付诸实践。有关详细信息,请参见Visual Basic 中的接口。
Delegates
代表
Delegates are objects that can call the methods of objects on your behalf and are sometimes described as type-safe, object-oriented function pointers. You can use delegates to let procedures specify an event handler method that runs when an event occurs. You can also use delegates with multithreaded applications. For details, see Delegates and the AddressOf Operator.
委托是可以代表您调用对象方法的对象,有时被描述为类型安全、面向对象的函数指针。您可以使用委托让过程指定在事件发生时运行的事件处理程序方法。您还可以在多线程应用程序中使用委托。有关详细信息,请参阅委托和 AddressOf 运算符。
Shared Members
共享成员
Shared members are properties, procedures, and fields that are shared by all instances of a class. Shared data members are useful when multiple objects need to use information that is common to all objects. You can use shared class methods without first creating an object from a class. For details, see Shared Members in Visual Basic. References
共享成员是由类的所有实例共享的属性、过程和字段。当多个对象需要使用所有对象共有的信息时,共享数据成员很有用。您可以使用共享类方法,而无需先从类创建对象。有关详细信息,请参见Visual Basic 中的共享成员。参考
You can use References to use objects defined in other assemblies. In VB.Net, references point to assemblies instead of type libraries. For details, see References and the Imports Statement.
您可以使用引用来使用在其他程序集中定义的对象。在 VB.Net 中,引用指向程序集而不是类型库。有关详细信息,请参阅参考资料和 Imports 声明。
Namespaces
命名空间
Namespaces prevent naming conflicts by organizing classes, interfaces, and methods into hierarchies. For details, see Namespaces in Visual Basic.
命名空间通过将类、接口和方法组织成层次结构来防止命名冲突。有关详细信息,请参见Visual Basic 中的命名空间。
Assemblies
组件
Assemblies replace and extend the capabilities of type libraries by describing all the required files for a particular component or application. An assembly can contain one or more namespaces. For details, see Assemblies.
程序集通过描述特定组件或应用程序的所有必需文件来替换和扩展类型库的功能。一个程序集可以包含一个或多个命名空间。有关详细信息,请参阅组件。
Attributes
属性
You can use attributes to provide additional information about program elements. For example, you can use an attribute to specify which methods in a class should be exposed when the class is used as a XML Web service. For details, see Attributes in Visual Basic.
您可以使用属性来提供有关程序元素的附加信息。例如,您可以使用属性来指定当类用作 XML Web 服务时应该公开类中的哪些方法。有关详细信息,请参见Visual Basic 中的属性。
Multithreading
多线程
You can use VB.Net to write applications that can perform multiple tasks independently. A task that can hold up other tasks can execute on a separate thread, a process known as multithreading. By causing complicated tasks to run on threads that are separate from your user interface, multithreading makes your applications more responsive to user input. For details, see Multithreaded Applications.
您可以使用 VB.Net 编写可以独立执行多项任务的应用程序。可以阻止其他任务的任务可以在单独的线程上执行,这个过程称为多线程。通过让复杂的任务在与用户界面分离的线程上运行,多线程使您的应用程序对用户输入的响应更快。有关详细信息,请参阅多线程应用程序。
Bit Shift Operators
位移运算符
VB.Net now supports arithmetic left- and right-shift operations on integral data types (Byte, Short, Integer, and Long) as well as on unsigned types (UShort, UInteger, and ULong). Arithmetic shifts are not circular, which means the bits shifted off one end of the result are not reintroduced at the other end. The corresponding assignment operators are provided as well. For details, see Bit Shift Operators and Assignment Operators.
VB.Net 现在支持对整数数据类型(Byte、Short、Integer 和 Long)以及无符号类型(UShort、UInteger 和 ULong)进行算术左移和右移运算。算术移位不是循环的,这意味着从结果一端移出的位不会在另一端重新引入。还提供了相应的赋值运算符。有关详细信息,请参阅位移运算符和赋值运算符。
Loop Variable Declaration
循环变量声明
You can use VB.Net to declare a loop variable as part of a For or For Each loop. You can include an As clause for the variable in the For or For Each statement, provided no variable of that name has been declared outside the loop. The scope of a loop variable declared in this manner is the loop itself. For details, see For...Next Statement (Visual Basic)and For Each...Next Statement (Visual Basic).
您可以使用 VB.Net 将循环变量声明为 For 或 For Each 循环的一部分。您可以在 For 或 For Each 语句中为变量包含一个 As 子句,前提是没有在循环外声明该名称的变量。以这种方式声明的循环变量的范围是循环本身。有关详细信息,请参见For...Next Statement (Visual Basic)和For Each...Next Statement (Visual Basic)。
Further informations:
更多信息:
- http://social.msdn.microsoft.com/Forums/en-SG/Vsexpressvb/thread/15f1ed35-47c4-4ae0-a8a6-16bad23f6947
- http://msdn.microsoft.com/en-us/library/ms172618.aspx
- http://msdn.microsoft.com/en-us/library/y17w47af.aspx
- http://www.thescarms.com/vbasic/vb6vsvbnet.aspx
- http://www.programmersheaven.com/2/FAQ-VBNET-VB6-VBNET-Differences
- What's New in the Visual Basic Language for Visual Basic 6.0 Users
- http://social.msdn.microsoft.com/Forums/en-SG/Vsexpressvb/thread/15f1ed35-47c4-4ae0-a8a6-16bad23f6947
- http://msdn.microsoft.com/en-us/library/ms172618.aspx
- http://msdn.microsoft.com/en-us/library/y17w47af.aspx
- http://www.thescarms.com/vbasic/vb6vsvbnet.aspx
- http://www.programmersheaven.com/2/FAQ-VBNET-VB6-VBNET-Differences
- Visual Basic 6.0 用户的 Visual Basic 语言新增功能
Edit: as commented some features like constructors were already supported in VB6(in a different way), have a look at the last link what takes that more into account
编辑:正如所评论的,VB6 中已经支持了一些像构造函数这样的功能(以不同的方式),看看最后一个链接是什么考虑了更多
回答by SharpAffair
Classic VB doesn't support most OOP features, while VB.NET does.
经典 VB 不支持大多数 OOP 功能,而 VB.NET 支持。
回答by decyclone
Major differences are Version Number and Object Orientation.
主要区别在于版本号和面向对象。
Up to version 6, it was known as VB. From version 7, which was released with .Net 1.0, it was known as VB.NET.
在第 6 版之前,它被称为 VB。从随 .Net 1.0 发布的第 7 版开始,它被称为 VB.NET。
It was completely revamped in version 7 to become more streamlined with .Net Framework (CLI & CLS compatibility) and other languages such as C# and Java.
它在第 7 版中进行了全面改进,以通过 .Net Framework(CLI 和 CLS 兼容性)和其他语言(如 C# 和 Java)变得更加精简。
In this transition, several changes caused broken backward compatibility with previous versions. That is why Microsoft provided a few tools in Visual Studio to convert old VB6 apps into .Net.
在此转换中,一些更改导致与以前版本的向后兼容性中断。这就是为什么 Microsoft 在 Visual Studio 中提供了一些工具来将旧的 VB6 应用程序转换为 .Net。

