Table 1-5. Visual Basic .NET and Visual C# Differences Feature
Visual Basic .NET Visual C# .NET
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: Use braces to declare functional blocks of code:
Sub Show(strX as String) void Show(string strX)
Response.Write(strX) {
End Sub Response.Write(strX);
}
Type conversion
Implicit type conversions are permitted by default: Implicit type conversions are limited to operations that
Dim X As Integer are guaranteed not to lose information, such as converting from int to float:
X = 3.14 ' OK int X = 0;
You can limit conversions by including an Option Strict On float Y = X; // OK
statement at the beginning of modules.
Other type conversions are performed explicitly by casts:
Y = 3.14F;
X = (int)Y; //Cast, OK.
Or, by using type conversion methods:
string Z;
Z = Y.ToString();
Arrays Array elements are specified using square brackets:
Array elements are specified using parentheses: arrFruit[1] = "Apple";
arrFruit(1) = "Apple"
Methods
You can omit parentheses after method names if arguments are omitted: You must include parentheses after all methods:
strX = objX.ToString strX = objX.ToString();
Statement termination
Statements are terminated by carriage return: Statements are terminated by the semicolon (;):
Response.Write("Hello") Response.Write("Hello");
Statement continuation
Statements are continued using the underscore (_): Statements continue until the semicolon (;) and can span
intX = System.Math.PI * _ multiple lines if needed:
intRadius intX = System.Math.PI *
intRadius;
String operator
Use the ampersand (&) or plus sign (+) to join strings: Use the plus sign (+) to join strings:
strFruit = "Apples" & _ strFruit = "Apples" +
" Oranges" " Oranges";
Comparison operators
Use =, >, <, >=, <=, <> to compare values: Use ==, >, <, >=, <=, != to compare values:
If intX >= 5 Then if (intX >= 5)
Negation
Use the Not keyword to express logical negation: Use the ! operator to express logical negation:
If Not IsPostBack Then if (!IsPostBack)
Object comparison
Use the Is keyword to compare object variables: Use == to compare object variables:
If objX Is objY Then if (objX == objY)
Object existence
Use the Nothing keyword or the IsNothing function to check Use the null keyword to check whether an object exists:
whether an object exists:
If IsNothing(objX) Then if (objX == null)