Programming Tutorials

Visual Basic .NET Vs Visual C# - (Differences)

By: Ram Babu in Asp.net Tutorials on 2008-11-26  

ASP.NET and, indeed, the whole .NET Framework are programming language-independent. That means you can choose any language that has implemented a CLR-compliant compiler. In addition to developing its own programming languages, Microsoft has formed partnerships with many language vendors to provide .NET support for Perl, Pascal, Eiffel, Cobol, Python, Smalltalk, and other programming languages.

Visual Basic .NET and Visual C#  are functionally equivalent, which means that they each provide equal abilities to create Web applications. The differences between the two languages are syntactical and stylistic.

Most current programmers will choose the language they are most familiar with. Current Visual Basic programmers will be more comfortable developing Web applications in Visual Basic .NET; C or C++ programmers will be more comfortable developing with Visual C#.

If you are new to programming or if you are choosing to extend your programming skills to new languages, learning both Visual Basic .NET and Visual C# is a practical goal. This is especially true when you create Web applications, since most of the tasks are performed through the .NET Framework classes, which means Visual Basic .NET code and Visual C# code often look nearly identical.

Table below summarizes some significant differences between Visual Basic .NET and Visual C#. This information is useful to keep in mind if you are choosing a programming language for the first time or if you are planning to switch between languages.

Visual Basic .NET and Visual C# Differences

Feature

Visual Basic .NET

Visual C# .NET

Case sensitive

Not case sensitive:

response.write("Yo") ' OK

Case sensitive:

response.write("Yo"); // Error Response.Write("Yo"); // OK

Functional blocks

Use beginning and ending statements to declare functional blocks of code:

Sub Show(strX as String)
  Response.Write(strX)
End Sub

Use braces to declare functional blocks of code:

void Show (string strX)
{
Response.Write(strX);
}

Type conversion

Implicit type conversions are permitted by default:

Dim intX As Integer
intX = 3.14  ' Permitted

You can limit conversions by including an Option Strict On statement at the beginning of modules.

Type conversions are performed explicitly by casts:

int intX;
intX = 3.14; // Error!
intX = (int)3.14; //Cast, OK.

Or, use type conversion methods:

string strX;
strX = intX.ToString();

Arrays

Array elements are specified using parentheses:

arrFruit(1) = "Apple"

Array elements are specified using square brackets:

arrFruit[1] = "Apple";

Methods

You can omit parentheses after method names if arguments are omitted:

strX = objX.ToString

You must include parentheses after all methods:

strX = objX.ToString();

Statement termination

Statements are terminated by carriage return:

Response.Write("Hello")

Statements are terminated by the semicolon (;):

Response.Write("Hello");

Statement continuation

Statements are continued using the underscore (_):

intX = System.Math.Pi * _
  intRadius

Statements continue until the semicolon (;) and can span multiple lines if needed:

intX = System.Math.PI * 
  intRadius;

String operator

Use the ampersand (&) or plus sign (+) to join strings:

strFruit = "Apples" & _
  " Oranges"

Use the plus sign (+) to join strings:

strFruit = "Apples" + 
  " Oranges";

Comparison operators

Use =, >, <, >=, <=, <> to compare values:

If intX >= 5 Then

Use ==, >, <, >=, <=, != to compare values:

if (intX >= 5)

Negation

Use the Not keyword to express logical negation:

If Not IsPostBack Then

Use the ! operator to express logical negation:

if (!IsPostBack)

Object comparison

Use the Is keyword to compare object variables:

If objX Is objY Then

Use == to compare object variables:

if (objX == objY)

Object existence

Use the Nothing keyword or the IsNothing function to check if an object exists:

If IsNothing(objX) Then

Use the null keyword to check if an object exists:

if (objX == null)

In addition to the differences shown in Table above, there are significant keyword differences between the two languages. The Visual Studio .NET Help topic "Language Equivalents" provides a complete comparison of Visual Basic .NET, Visual C#, and other Microsoft languages.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Asp.net )

Getting values from appsettings.json ASP.NET

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

Call an Action in a controller when user clicks a button in View

Button that is only clickable when the checkbox is checked

Visual Basic .NET Vs Visual C# - (Differences)

Severity Code Description Project File Line Suppression State Error CS0103 The name 'JsonConvert' does not exist in the current context.

Things to note when changing a function to async in your controller

Do we need to redeploy the webapp when appsettings.json change?s

Development Mode in IIS for Asp.net projects

Passing a model globally to all Views in your Asp.net webapp

ActiveX component can't create object: 'CDONTS.NewMail' - ASP

Pass the same model to multiple views within the same controller

AmbiguousMatchException: The request matched multiple endpoints.

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Latest Articles (in Asp.net)

Things to note when changing a function to async in your controller

AmbiguousMatchException: The request matched multiple endpoints.

Call an Action in a controller when user clicks a button in View

Button that is only clickable when the checkbox is checked

Pass the same model to multiple views within the same controller

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Severity Code Description Project File Line Suppression State Error CS0103 The name 'JsonConvert' does not exist in the current context.

Passing a model globally to all Views in your Asp.net webapp

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

One client credential type required either: ClientSecret, Certificate, ClientAssertion or AppTokenProvider must be defined when creating a Confidential Client. Only specify one

Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of the same dependent assembly.

Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)

Pagination in ASP.net core application

Microsoft.Identity vs Microsoft.IdentityModel.Clients.ActiveDirectory

Related Tutorials

Things to note when changing a function to async in your controller

AmbiguousMatchException: The request matched multiple endpoints.

Call an Action in a controller when user clicks a button in View

Button that is only clickable when the checkbox is checked

Pass the same model to multiple views within the same controller

Severity Code Description Project File Line Suppression State Error CS0103 The name 'Encoding' does not exist in the current context

Severity Code Description Project File Line Suppression State Error CS0103 The name 'JsonConvert' does not exist in the current context.

Passing a model globally to all Views in your Asp.net webapp

Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'JToken' could not be found.

Severity Code Description Project File Line Suppression State Error CS0308 The non-generic type 'List' cannot be used with type arguments.

One client credential type required either: ClientSecret, Certificate, ClientAssertion or AppTokenProvider must be defined when creating a Confidential Client. Only specify one

Severity Code Description Project File Line Suppression State Warning Found conflicts between different versions of the same dependent assembly.

Severity Code Description Project File Line Suppression State Error CS1061 'string[]' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'string[]' could be found (are you missing a using directive or an assembly reference?)

Pagination in ASP.net core application

Microsoft.Identity vs Microsoft.IdentityModel.Clients.ActiveDirectory