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 |
Dim x As Long = 5
Dim c As New _
Car(FuelTypeEnum.Gas) |
// 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 |
With objExpr
<.member>
<.member>
End With |
n/a |
Structured exception handling |
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 |
Dim a() As Long |
int[] x = new int[5]; |
Initialize an array |
Dim a() As Long = {3, 4, 5}
|
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 |