The biggest differences between the languages fall into the following categories:
Visual Basic .NET |
Visual C# .NET |
Dim i, j As Integer |
int i, j; |
Dim i As Integer = 7 |
int i = 7; |
Dim i(6) As Integer or Dim i() As Integer = New Integer(6) {} |
int[] i = new int[6]; |
Dim con As SqlConnection |
SqlConnection con; |
Dim x As New Y("ABC") or Dim x As Y = New Y("ABC") |
Y x = new Y("ABC"); |
Visual Basic .NET | Visual C# .NET | .NET Framework |
Boolean | bool | System.Boolean |
Byte | byte | System.Byte |
Short | short | System.Int16 |
Integer | int | System.Int32 |
Long | long | System.Int64 |
Single | float | System.Single |
Double | double | System.Double |
Decimal | decimal | System.Decimal |
Date | System.DateTime | System.DateTime |
String | string | System.String |
Char | char | System.Char |
Object | object | System.Object |
n/a | sbyte | System.Sbyte |
n/a | ushort | System.UInt16 |
n/a | uint | System.UInt32 |
n/a | ulong | System.UInt64 |
3. Statement Termination | |
Visual Basic .NET | Visual C# .NET |
A = 5 B = 7 : C = 8 MySub (Arg1, _ | A = 5; B = 7; C = 8; MySub (Arg1, |
4. Statement Blocks
Visual Basic .NET | Visual C# .NET |
If A = 5 Then End If | If (a == 5) { } or if (a == 5) //This is not part of the if |
Purpose | Visual Basic .NET | Visual C# .NET |
Declare an array | Dim a() As Long Dim a(3, 5) as Integer | int[] x = new int[5]; |
Initialize an array | Dim a() As Long = {3, 4, 5} | int[] x = new int[5] {1, 2, 3, 4, 5}; |
Reallocate array | Redim | n/a |
Functions Arguments | X= A(5) MySub (A, B, C) | MySub(A, B, C); |
Property Indexes | Y = MyDataSet.Tables_ ("Author").Rows(5)._ Columns("AuthorID") | Y = MyDataSet.Tables["Author"].Rows[5].Columns["AuthorID"] |
6. Operators
Operator | Visual Basic .NET | Visual C# .NET |
Additive | ||
Addition | + | + |
Subtraction | - | - |
Multiplicative | ||
Multiplication | * | * |
Division | / | / |
Integer division | \ | / (depending on the operands) |
Modulus (division returning only the remainder) | Mod | % |
Exponentiation | ^ | n/a |
Logical | Visual Basic .NET | Visual C# .NET |
Logical AND, OR | And | && |
Logical OR | Or | || |
Conditional | ||
Conditional | IIf | ?: |
Pointer to member | ||
Pointer to member | n/a | . (Unsafe mode only) |
7. Conditional Statements
Conditional Statement | Visual Basic .NET | Visual C# .NET |
Decision structure (selection) | Select Case …, Case, Case Else, End Select | switch, case, default, |
Decision structure (if … then) | If … Then, ElseIf … Then, Else, End If | if, else |
Loop structure (conditional) | While… End While, Do [While, Until] …, Loop [While, Until] | do, while, continue |
Loop structure (iteration) | For …, [Exit For,] Next For Each …, [Exit For,] Next | for, foreach |
Control flow statement | Exit, GoTo, Stop, End, Return, | break, continue, goto, return, throw |
Purpose |
Visual Basic .NET |
Visual C# .NET |
Object Oriented Programming |
||
Indicates a class constructor |
Public Class Class1 Public Sub New(..) MyBase.New … End Sub … End Class Note: You have to call the base class constructor explicitly in Visual Basic .NET. |
public class Class1 { public Class1(..) { … } …. } Note: The call to the base class constructor (base()) is generated automatically by the compiler in Visual C# .NET if you do not include constructor initializers. |
Indicates a class destructor Note: The Destructor or Finalize method is called by garbage collection. |
Protected Overrides Sub Finalize() m_Gadget = Nothing m_Gear = Nothing MyBase.Finalize() End Sub |
public class Class1 { public ~Class1() { …. } } |
Declares a class |
Class |
class |
Indicates class inheritance |
Public Class A Inherits B … End Class |
public class A : B { … } |