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.NET | Description |
| using | Imports | Allows methods to be called without fully qualifying with Namespace name |
| this | Me | Refer to the current object |
| base | MyBase | Refer to the base class |
| static | Shared | Specifies that a member is shared by all instances of a class. To call the member, an instance of the class is not required. |
| no equivalent | Static | Specifies that a local variable's value is preserved between calls. |
| not required | ByVal | Passing parameters by value |
| ref | ByRef | Passing parameters by reference |
| enum | Enum | Declare an enumerator |
| struct | Structure | Declare a structure |
| obj == null | obj = Nothing | Check whether an object is not ponit to anything |
| on by default and not changable | Option Explicit | Specifies that all variables must be declared. |
| delegate | AddressOf | Use the address of a method |
| no equivalent | With ... 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. |
| lock | SynLock | Threading primitives. |
| sealed | NotInheritable | Specifies that a class cannot be used as a base class (cannot be inherited). |
| sealed | NotOverridable | Specifies that a method cannot be overriden. |
| abstract | MustInherit | Specifies that a class can only be inherited (an instance of the class cannot be created). |
| abstract | MustOverride | Specifies that a method must be implemented in a derived class. |
| virtual | Overridable | Specifies that a member can be overriden |
| override | Overrides | Specifies that a member is overriding another member. |
| not required | Overloads | Specifies that a member is overloading another member. |
| class Class1:I1 | Implements I1 | Specifies that the class (Class1) implements the interface I1. |
| class Class1:BaseClass1 | Inherits BaseClass1 | Specifies that the class (Class1) inherits class BaseClass1. |
| Class1 | New | Constructor method, called when object is created. Class1 is classname. |
| ~Class1 | Finalize | Method called by system just before garbage collection reclaims object, known as destrutor method. Class1 is class name. |

0 comments:
Post a Comment