Language Syntaxes of VB.NET and C#
(October 9, 2003)
Language Differences
VB.NET C# Description
| NotInheritable |
sealed |
Specifies that a class cannot be used as a base class, i.e. that it cannot be inherited. |
| NotOverridable | sealed | Specifies that a method cannot be overriden. |
| MustInherit | abstract | Specifies that a class can only be inherited (an instance of the class cannot be created). |
| MustOverride | abstract | Specified that a method must be implemented in a derived class. |
| Overridable | virtual | Specifies that a member can be overriden. |
| Shared | static | Specifies that a member is shared by all instances of a class. An instance of the class is not required to call the member. |
| Static | no equivalent | Specifies that a local variable's value is preserved between calls. |
| Public | public |
Class/member is visible outside of project or assembly. |
| Friend | internal | Class/member is invisible outside of the assembly. |
| Private | private | Class/member is visible only within the project. |
| Overloads | not required | Specifies that a member is overloading another member. |
| Overrides | override |
Specifies that a member is overriding another member. |
| Implements I1 | class C1:I1 | Specifies that the class (C1) implements the interface I1. |
| Inherits C2 | class C1:C2 | Specifies that the class (C1) inherits class C2. |
|
Implements I1 Inherits C2 |
class C1:C2,I1 | Specifies that the class (C1) implements the interface I1 and inherits class C2. |
| Shadows | new | |
| Finalize | ~C1 (destructor) | Method called by system just before garbage collection reclaims object. C1 is classname. |
| New | C1 | Constructor method, called when object is created. C1 is classname. |
| Dim x as Int32 | Int32 x | Declares variable x as type System.Int32. |
|
Dim t1 As New SomeType() |
using(SomeType t1 = new SomeType()) { t1.SomeMethod; } |
|
| Imports | using | Allows methods to be called without fully qualifying with Namespace name. |
| <> | [] | Specifies parameters. |
|
Function x as Int32 Sub y |
Int32 x void y |
Specifies return values (Int32 and none). |
| _ | ; | Line continuation character in VB, end of line character in C#. |
|
AndAlso OrElse |
&& || |
Short circuit versions of And and Or. |
| not supported | << >> | Shift operators. |
|
X+=1 (x=x+1) X-=1 (x=x-1) also *=, /=, ^= etc.. |
x++ x-- |
Short cut incrementers. |
|
Dim x(4) as Int32 = 5 items (0 to 4) |
Int32[] x = new Int32[4]; = 4 items (0 to 3) |
Differences in array declarations and the number of elements created. |
| Dim x as Int32 | Int32 x = 0 | x initialised as zero automatically in VB. |
| ReDim Preserve | no equivalent | Redimensions an array. |
| Optional | need to overload sub instead | Specifies and optional parameter. |
| Select Case x Case True Case Else End Select |
switch(I) { case 1:break; default:break; }; |
|
|
ByVal ByRef |
not required ref |
Passing parameters by value and by reference. |
| Me | this | Refer to the current object. |
| MyBase | base | Refer to the base calss. |
| MyClass | no eqivalent | Make a non-virtual call to a virtual method of the current object. |
| Const |
const readonly |
Declare a constant. |
| Enum | enum | Declare an enumerator. |
| Structure | struct | Declare a structure. |
| no equivalent | volatile | Declare that an object can be modifed asynchronously. |
| obj = Nothing | obj == null | Test for an object variable that does not point to anything. |
| Option Explicit | on by default and not changable | Specify that all variables must be declared. |
| IsDBNull | no equivalent | Test for a database Null. |
| Default | must use indexer | Specify default method of a class. |
| WithEvents | no equivalent | Declare a variable whose events you wish to handle. |
| Handles | no equivalent | Specify that the method is an event sink. |
|
Try |
try{} |
Structured exception handling |
| If Number < 10 Then Digits = 1 ElseIf Number < 100 Then ' Condition evaluates to True so the next statement is executed. Digits = 2 Else Digits = 3 End If |
if (x > 10) { if (y > 20) Console.Write("Statement_1"); } else Console.Write("Statement_2"); |
Conditions. |
| For I = 1 To 10 For J = 1 To 10 For K = 1 To 10 ' Statements to operate with current values of I, J, and K. Next K Next J Next I |
for (int i = 1; i <= 5; i++) Console.WriteLine(i); |
Iterations. |
|
REM ' |
/* ... */ // |
Comment lines |
| not supported | /// | XML comment lines |
| Dim x As String = "Hello" Dim y As Char = GetChar(x, 1) |
string x = "hello"; char y; y = x[1]; |
Retrieve a character from a String. |
| AddressOf | delegate | Use the address of a method. |
| With ... End With | no equivalent | Evaluate an object one and use many times. |
| Dim a() as Long = {1,2,3} | int[] x = new int[4] {1,2,3,4}; | Initialise an array. |
|
Event RaiseEvent |
event | Declare and raise an event. |
| SyncLock | lock | Threading primitives. |
|
Defaults to Private Scope - Variable in class Defaults to Public Scope - Variable in Structure |
Defaults to Private Scope - Variable in class Defaults to Public Scope - struct |
|
| no equivalent |
public void ShowWord() |
An output parameter is a parameter that is passed from a called method to the method that called it, that is, the |
| see @
Visual Basic .NET |
@ |
srinivs nadella
I am a Sr. Software Engineer at Knowledge Infotech at Hyderabad, India. My work environemnt works on all Microsoft Technologies. I basically lover of Micorosoft.
User Reviews
Total of 1 reviewNice one
Written by Satya Puvvada on May 11, 2009Hi Srinivas,Nice collection between C# and VB.Net. Keep posting this kind of contentRegards, Satya






