Programming Difference between VB.NET and C#.NET


In this article, I will explain how to declare a variable in vb.net and c#.net. Simple example is given for using Comments, Assignment Statements, Conditional Statements, FOR Loops, WHILE Loops and select case Statements Programming Difference bewteen VB.net and C#.net

Programming Difference between VB.NET and C#.NET

1. Declaring Variables
Declaring Variables in VB.NET


Dim X as integer


Declaring Variables in C#.NET

Int X;



2. Comments

Comments in VB.NET


'this is a vb.net comment
Dim I as integer 'I is a integer variable



Comments in C#.NET


//single line comment

Exxample:
String name // name is a string variable

/* multiline
comment */

Exxample:
/* int i;
I=5;
*/


3. Assignment Statements

Assignment Statements in VB.NET


X = 7


Assignment Statements in C#.NET

X=67


4. Conditional Statements

Conditional Statements in VB.NET


If X<=Y then

Z+=X
X+=1
Else
Z+=X
X-=1
End If




Conditional Statements in C#.NET

 
If(X<=Y)
{
Z+=X;
X++;
}
Else
{
Z+=X
X--
}


5. FOR Loops

FOR Loops in VB.NET
For Loop


For n = 1 To 10
Console.WriteLine(n)
Next



For Each


Dim numb() As Integer = {1, 2, 3}
For Each number As Integer In numb
Console.WriteLine(number.ToString)
Next



FOR Loops in C#.NET


for (int i = 1; i <= 10; i++)
Console.WriteLine(
"The number is {0}", i);


For each


string[] strArray = new string[] { "test1", "test2", "test3", "test4", "test5" };

foreach (string str in strArray)
{
Console.WriteLine(str);
}
Console.ReadLine();



6.WHILE Loops

WHILE Loops in VB.NET


Dim n As Integer
While n < 10
' Same as n = n + 1.
n += 1
Console.WriteLine(n)
End While


WHILE Loops in C#.NET


int n1=0;
while (n1 < 10)
{
Console.WriteLine(n1);
n1++;
}


7. Selection Statements

Selection Statements in VB.NET



Dim number As Integer
Console.WriteLine("Please enter values from 0 to 2")
number = Console.ReadLine()

Select Case numer
Case 0
Console.WriteLine("zero is slected")
Case 1
Console.WriteLine("one is slected")
Case 2
Console.WriteLine("two is slected")
Case Else
Console.WriteLine("Default")
End Select
Console.ReadLine()





Selection Statements in C#.NET


Console.WriteLine("Select number 0 to 2");
Console.Write("Please enter your selection: ");
string s = Console.ReadLine();

switch (s)
{
case "0":
Console.WriteLine("zero is selected");
break;

case "1":
Console.WriteLine("one is selected");
break;
case "2":
Console.WriteLine("two is selected");
break;

default:
Console.WriteLine("You have not selected a valid operator");
break;

}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: