mskeel
Well-known member
The differences between C# and VB have been growing smaller and smaller with each .Net release to the point where translating between them is mostly a trivial task. Despite this, newcomers to VB.Net are overwhelmed and confused by the mass of curly braces, semicolons, and strange compiler errors when copying and pasting code. The truth is that when it comes to the .Net Framework, C# and VB.Net are almost identical but there still are some major differences in syntax that can be very confusing.
Ill start with some of the basics. Please feel free to add to this list. The point is not to have an exhaustive list of conversion recipes, but to bring together enough information so that a newcomer to VB with no C# knowledge can read C#.
If you see a mistake, PM the person who wrote it so they can fix it.
Comments
Declaring Variables
void functions/subs -- methods that do not return a value
Methods that return a value
Ill start with some of the basics. Please feel free to add to this list. The point is not to have an exhaustive list of conversion recipes, but to bring together enough information so that a newcomer to VB with no C# knowledge can read C#.
If you see a mistake, PM the person who wrote it so they can fix it.
Comments
C#:
//this is a one line comment
/* this is a
multi-line comment */
///<summary>This is an XML comment</summary>
Code:
this is a single line comment
<summary>This is an XML comment</summary>
Declaring Variables
C#:
int maxValue = 45;
MyClass super = new MyClass();
Code:
Dim maxValue as Integer = 45
Dim super1 as new MyClass
Dim super2 as MyClass = new MyClass
void functions/subs -- methods that do not return a value
C#:
public void SuperFunction()
{
//...
}
Code:
Public Sub SuperFunction()
...
End Sub
Methods that return a value
C#:
public string SuperFunction()
{
//...
}
public int AnotherSuperFunction()
{
//...
}
Code:
Public Function SuperFunction() As String
...
End Function
Public Function AnotherSuperFunction() As Integer
...
End Function
Last edited by a moderator: