Vb. NET vs. C # syntax Comparison

Source: Internet
Author: User

Recently read the code or write code, often the VB and C # Basic grammar mixed, for the convenience of viewing, a comparison of its similarities and differences:

Initialization of variables

VB.net automatically initializes all the variables to 0 or nothing. C # You are not allowed to use the variables until you initialize the variables.

Select parameters (Optional parameters)

C # does not provide a function selection parameter, but can still use overloaded methods to provide optional parameters

Definition of a static method

Both C # and vb.net are called Sharedin Class support for the static method, the fields,c#, and the static,vb.net, for example

Public Static void Staticmethod ()

{

Console.WriteLine ("No need to build objects to call");

}

Public Shared Sub Sharemethod ()

Console.WriteLine ("You can call a function without building an object")

End Sub

Switch and Select Case language

The switch language in C # lets you jump to a program block with a value or language. Each block is linked to a constant value. You can use multiple constants to create the following code with the case language method

Switch (i)

{

Case 4:

Case 5:

Break ;

Case 6:

Case 7:

Break ;

default :

Break ;

}

VB allows you to combine constants or more complex languages, as follows

Select Case I

Case 4, 5

Case 6 to 9

Case Else

End Select

Not only that, vb.net also allows you to use the variables in Select case in the same way that you use constants

Fax or URL call

All vb.net parameters are used to make sure that the ByVal and ByRef declarations are made, and that the C # parameters are all values unless declared with the ref key.

Virtual/overridable method

C # uses Virtual keys to announce that even a reference to the base Class is still a method of calling to the correct derivative. A function derived from the override declaration

VB.net uses the Overridable key to declare the virtual function, and it needs to use the Overrides key to declare the derived function.

Abstract/mustinherit method

C # uses the keyword abstract to target a method that requires a derived Class to be present,

VB.net uses the MustInherit keyword to do the same kind of labeling (used at the same time in Class and method).

Sealed/noinheritable Classes

C # uses the keyword Sealed to do the same thing with the NotInheritable keyword, which classs,vb.net cannot be inherited.

vb.net supports all CLS standard information types, and C # adds support for non-positive negative numbers.

The following table lists the bases of the two languages and whether they are compatible with the CLS

vb.net C# Compatible with CLS
Object Object Y
String String Y
  SByte N
Short Short Y
Integer Int Y
Long Long Y
Byte Byte Y
  UShort N
  UInt N
  ULong N
Single Float Y
Double Double Y
Boolean bool Y
Char Char Y
Decimal Decimal Y

Vb. NET vs. C # syntax Comparison

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.