Thursday, April 24, 2008

Syntax Differences of C# and VB.NET

Sometimes, I need to convert the codes from C# to VB.NET or from VB.NET to C#. So, I need to know some of the syntax differences of C# and VB.NET. The Table below shows some syntax differences of them:

C#VB.NETDescription

usingImportsAllows methods to be called without fully qualifying with Namespace name

thisMeRefer to the current object

baseMyBaseRefer to the base class

staticSharedSpecifies that a member is shared by all instances of a class. To call the member, an instance of the class is not required.

no equivalentStaticSpecifies that a local variable's value is preserved between calls.

not requiredByValPassing parameters by value

refByRefPassing parameters by reference

enumEnumDeclare an enumerator

structStructureDeclare a structure

obj == nullobj = NothingCheck whether an object is not ponit to anything

on by default and not changableOption ExplicitSpecifies that all variables must be declared.

delegateAddressOfUse the address of a method

no equivalentWith
 ...
End With
Evaluate an object one and use many times.

int[] x = new int[4] {1,2,3,4};Dim a() as Initialise an array.

lockSynLockThreading primitives.

sealedNotInheritableSpecifies that a class cannot be used as a base class (cannot be inherited).

sealedNotOverridableSpecifies that a method cannot be overriden.

abstractMustInheritSpecifies that a class can only be inherited (an instance of the class cannot be created).

abstractMustOverrideSpecifies that a method must be implemented in a derived class.

virtualOverridableSpecifies that a member can be overriden

overrideOverridesSpecifies that a member is overriding another member.

not requiredOverloadsSpecifies that a member is overloading another member.

class Class1:I1Implements I1Specifies that the class (Class1) implements the interface I1.

class Class1:BaseClass1Inherits BaseClass1Specifies that the class (Class1) inherits class BaseClass1.

Class1NewConstructor method, called when object is created. Class1 is classname.

~Class1FinalizeMethod called by system just before garbage collection reclaims object, known as destrutor method. Class1 is class name.

0 comments: