vbnet c# Keyword Differences

http://www.codeproject.com/KB/dotnet/vbnet_c__difference.aspx

Purpose VB.NET C#
Declare a variable Private, Public, Friend, Protected, Static1, Shared, Dim declarators (keywords include user-defined types and built-in types)
Declare a named constant Const const
Create a new object New, CreateObject() new
Function/method does not return a value Sub void
Overload a function or method (Visual Basic: overload a procedure or method) Overloads (No language keyword required for this purpose)
Refer to the current object Me this
Make a nonvirtual call to a virtual method of the current object MyClass n/a
Retrieve character from a string GetChar Function []
Declare a compound data type (Visual Basic: Structure) Structure <members> End Structure struct, class, interface
Initialize an object (constructors) Sub New() Constructors, or system default type constructors
Terminate an object directly n/a n/a
Method called by the system just before garbage collection reclaims an object7 Finalize destructor
Initialize a variable where it is declared
Collapse | Copy Code
Dim x As Long = 5
Collapse | Copy Code
Dim c As New _
   Car(FuelTypeEnum.Gas)
Collapse | Copy Code
// initialize to a value:
int x = 123;
// or use default 
// constructor:
int x = new int();
Take the address of a function AddressOf (For class members, this operator returns a reference to a function in the form of a delegate instance) delegate
Declare that an object can be modified asynchronously n/a volatile
Force explicit declaration of variables Option Explicit n/a. (All variables must be declared prior to use)
Test for an object variable that does not refer to an object obj = Nothing obj == null
Value of an object variable that does not refer to an object Nothing null
Test for a database null expression IsDbNull n/a
Test whether a Variant variable has been initialized n/a n/a
Define a default property Default by using indexers
Refer to a base class MyBase base
Declare an interface Interface interface
Specify an interface to be implemented Implements (statement) class C1 : I1
Declare a class Class <implementation> class
Specify that a class can only be inherited. An instance of the class cannot be created. MustInherit abstract
Specify that a class cannot be inherited NotInheritable sealed
Declare an enumerated type Enum <members> End Enum enum
Declare a class constant Const const (Applied to a field declaration)
Derive a class from a base class Inherits C2 class C1 : C2
Override a method Overrides override
Declare a method that must be implemented in a deriving class MustOverride abstract
Declare a method that can’t be overridden NotOverridable (Methods are not overridable by default.) sealed
Declare a virtual method, property (Visual Basic), or property accessor (C#, C++) Overridable virtual
Hide a base class member in a derived class Shadowing n/a
Declare a typesafe reference to a class method Delegate delegate
Specify that a variable can contain an object whose events you wish to handle WithEvents (Write code – no specific keyword)
Specify the events for which an event procedure will be called Handles (Event procedures can still be associated with a WithEvents variable by naming pattern.) n/a
Evaluate an object expression once, in order to access multiple members
Collapse | Copy Code
With objExpr 
  <.member>
  <.member> 
End With
n/a
Structured exception handling
Collapse | Copy Code
Try <attempt>
Catch
<handle errors>
Finally
<always execute>
End Try
try, catch, finally, throw
Decision structure (selection) Select Case ..., Case, Case Else, End Select switch, case, default, goto, break
Decision structure (if … then) If ... Then, ElseIf ... Then, Else, End If if, else
Loop structure (conditional) While, Do [While, Until] ..., Loop [While, Until] do, while, continue
Loop structure (iteration) For ..., [Exit For], Next
For Each ..., [Exit For,] Next
for, foreach
Declare an array
Collapse | Copy Code
Dim a() As Long
Collapse | Copy Code
int[] x = new int[5];
Initialize an array
Collapse | Copy Code
Dim a() As Long = {3, 4, 5}
Collapse | Copy Code
int[] x = new int[5] {
        1, 2, 3, 4, 5};
Reallocate array Redim n/a
Visible outside the project or assembly Public public
Invisible outside the assembly (C#/Visual Basic) or within the package (Visual J#, JScript) Friend internal
Visible only within the project (for nested classes, within the enclosing class) Private private
Accessible outside class and project or module Public public
Accessible outside the class, but within the project Friend internal
Only accessible within class or module Private private
Only accessible to current and derived classes Protected protected
Preserve procedure’s local variables Static n/a
Shared by all instances of a class Shared static
Comment code '
Rem
//, /* */ for multi-line comments
/// for XML comments
Case-sensitive? No Yes
Call Windows API Declare <API> use Platform Invoke
Declare and raise an event Event, RaiseEvent event
Threading primitives SyncLock lock
Go to Goto goto
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: