VB.Net vs C-Sharp

Saturday, 7 January 2012
VB.Net vs C-Sharp Comparison is a very concise reference for commands you use every day. Print it out, hang it on the wall where it will not get lost, and use it every day.

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";
MethodsStatement 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 operatorsUse =, >, <, >=, <=, <> 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)

0 comments:

Post a Comment