Terry's WebLog

Your potential, our passion

some difference between c# and vb.net

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";

Methods

You can omit parentheses after method names if arguments are omitted:

strX = objX.ToString

You must include parentheses after all methods:

strX = objX.ToString();

Statement 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 operators

Use =, >, <, >=, <=, <> 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)

Posted: Aug 26 2004, 05:22 PM by freeswing | with 8 comment(s)
Filed under:

Comments

Karl said:

Three picky points:

[a] VB.Net not case sensitive:
I've always found this misleading for two reasons:
- String comparisons are by default
- The CLR is, so XPath's are case-sensitive whether or not you use VB.Net

[b] + shouldn't be used to join strings (as per Paul Vick)

[c] IsNothing is not the same as objx == null:
IsNothing maps to Information.IsNothing(RuntimeHelpers.GetObjectValue(obj1))
Which I have no clue what that is, but doesn't look good. Far better to use if objx is nothing then

Karl
# August 26, 2004 8:42 AM

janet said:

i m using C# .NET to implement my final year project which is a system that based on PDA.

the reason that i use C#.NET because i feel more confidence on lanaguage that similar with Java. besides that, .net also enable me to develop portable application easily.

but, my supervisor asks me why i prefer c#. net rather than vb.Net?

i duno the actual answer. so could you give me some facts that indicate c#.Net is suitable to be used to develop pda application?
# September 2, 2004 4:05 AM

janet said:

i m using C# .NET to implement my final year project which is a system that based on PDA.

the reason that i use C#.NET because i feel more confidence on lanaguage that similar with Java. besides that, .net also enable me to develop portable application easily.

but, my supervisor asks me why i prefer c#. net rather than vb.Net?

i duno the actual answer. so could you give me some facts that indicate c#.Net is suitable to be used to develop pda application?
# September 2, 2004 4:05 AM

janet said:

i m using C# .NET to implement my final year project which is a system that based on PDA.

the reason that i use C#.NET because i feel more confidence on lanaguage that similar with Java. besides that, .net also enable me to develop portable application easily.

but, my supervisor asks me why i prefer c#. net rather than vb.Net?

i duno the actual answer. so could you give me some facts that indicate c#.Net is suitable to be used to develop pda application?
# September 2, 2004 4:05 AM

John said:

"the reason that I use C#.NET because i feel more confidence on language that is similar with Java."

While the language constructs and syntax may be similar, C# is nothing like Java. Additionally, when given the option to use VB.NET or C#, your choice is simply that, a choice. The resultant MSIL code for either language is virtually identical. I have written many applications, some I have converted from VB to C#, and the reverse is also true. Those applications included some for my PDA and both languages have proved themselves to be suitable for developing applications for the PDA.
# September 22, 2004 1:20 PM

Thiran said:

we are planning to build a calculator for PDA (Military purpose) i just want to know weather we can develop it using VB.net.

# January 8, 2008 7:27 AM

azeem said:

i prefer c#.net because vb.net is a week typed language.

# November 15, 2008 11:59 AM

buy cheap oem software said:

hYQqDz Thanks:) Cool topic, write more often! You manage with it perfctly:D

# February 12, 2012 2:15 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)