Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Keywords Compared in Different Languages 

This topic lists common programming tasks that can be summarized with a language keyword. For more information about tasks that need code examples, see Programming Concepts Compared in Different Languages with Code Examples.

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Declare a variable

Dim Statement (Visual Basic)

Public (Visual Basic)

Friend (Visual Basic)

Protected (Visual Basic)

Private (Visual Basic)

Shared (Visual Basic)

Static (Visual Basic) 1

public

protected

private

static

final

volatile

transient

declarators (concept, not keyword)

declarators (keywords include user-defined types and built-in types)

var

[implicit declaration]

PUBLIC

LOCAL

PRIVATE

Declare a named constant

Const

final

const

const

readonly

const

#DEFINE

Create a new instance of a class

New

new

new

gcnew

new

new

NEWOBJECT( ) function

Create a new object

CreateObject()

new

CoCreateInstance() (for COM objects)

new 

new ActiveXObject()

CREATEOBJECT( ) function

Assign an object to an object variable

=

=

=

=

=

=

STORE

Function/method does not return a value

Sub 2

void

void

void

void

Void (COM servers only)

Overload a function or method (Visual Basic: overload a procedure or method)

Overloads

(No language keyword required for this purpose)

(No language keyword required for this purpose)

(No language keyword required for this purpose)

(No language keyword required for this purpose)

(No language keyword required for this purpose)

Refer to the current object

Me 3

this

this

this

this

this

thisform

Make a nonvirtual call to a virtual method of the current object

MyClass

n/a

MyClass::Func1(), where MyClass is a C++ class with a member function Func1.

n/a

n/a

n/a

Retrieve character from a string

str(10) where str is a string

string

str[10] where str is a string

string

*(p + 10) or p[10] where p is a char* or wchar_t*

str[10] where str is a string

string

str[10], where str is a string

charAt

substring

substr

SUBSTR( )

Declare a compound data type (structure)

Structure

class, interface

class

struct

union

__interface

struct

class

interface

class, interface

n/a

Initialize an object (constructor)

Sub New() 5

Constructors (concept, not keyword)

constructors (concept, not keyword)

Constructors, or system default type constructors

Class Constructors

Constructor (concept, not keyword)6

Init event

Terminate an object directly

n/a

n/a

~ ClassName

n/a

n/a

n/a

Method called by the system just before garbage collection reclaims an object7

Finalize (in Visual Basic 6.0, Class_Terminate)

finally

destructor

Destructors

n/a

Destroy event

Initialize a variable where it is declared

Dim x As Long = 5

Dim c As New Car(FuelTypeEnum.Gas)

int x = 5;

// or initialize by constructor:

C c(10);

int x=5;

// initialize to a value:

int x = 123;

// or use default constructor:

int x = new int();

var x = 5

var y : car = new car()

LOCAL x

x = 5

Take the address of a function

AddressOf (This operator returns a reference to a function in the form of a delegate instance)

delegate

multicast

/** @delgate */

delegate

delegate

Use the name of the function without parentheses

n/a

Callback

Pass the address of one function to another that calls the invoker back. For an example, see How to: Pass Procedures to Another Procedure in Visual Basic.

Pass the address of one function to another that calls the invoker back. For an example, see Using Callback Functions.

CALLBACK (a standard type)

callback (IDL attribute)

delegate

n/a

n/a

Declare that an object can be modified asynchronously

n/a

volatile

volatile

volatile

n/a

n/a

Force explicit declaration of variables

Option Explicit

n/a (All variables must be declared prior to use)

n/a (All variables must be declared prior to use)

n/a (All variables must be declared prior to use)

fast mode (on by default)

_VFP.LanguageOptions NEW 

Test for an object variable that does not refer to an object

obj Is Nothing

pObj == null

pobj == NULL

obj == null

obj == undefined

obj == null

VARTYPE(obj)=="0"

Value of an object variable that does not refer to an object

Nothing

null

nullptr

null

null

undefined

.F.

Test for a database null expression

IsDbNull

Supported by various data types in the System.Data.SqlTypes namespace

n/a

n/a

x == null

ISNULL( )

Test whether a Variant variable has been initialized

n/a

n/a

n/a

n/a

x == undefined

EMPTY( )

Define a default property

Default

n/a

property

Indexers

n/a

n/a

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Refer to a base class

MyBase

super

__super

base

super

BaseClass property

ParentClass property

DODEFAULT()

Class::member

Declare an interface

Interface

interface

__interface

interface class

interface

interface

DEFINE CLASS

Specify an interface to be implemented

Implements (statement)

implements (clause on class declaration)

(Just derive from the interface)

class C1 : public I1

class C1 : I1

Interfaces

IMPLEMENTS

IMPLEMENTS NEW 

Declare a class

Class

class

class

Classes and Structs (Managed)

class

class

DEFINE CLASS MyClass AS <ParentClass>

Declare a module

Module Statement

n/a

static class

static class

n/a

n/a

Declare a partial definition of a class or structure

Partial (Visual Basic)

n/a

n/a

Partial

n/a

n/a

Specify that a class can only be inherited. An instance of the class cannot be created

MustInherit

abstract

abstract (Visual C++)

abstract

abstract

n/a

Specify that a class cannot be inherited

NotInheritable

final

sealed

sealed

final

n/a

Declare an enumerated type

Enum <members> End Enum

n/a

enum

enum

enum

n/a

Declare a class constant

Const

static final (Applied to a field declaration)

const

const (Applied to a field declaration)

const

#DEFINE

Derive a class from a base class

Inherits C2

class C1 extends C2

Class C1 : public Base (No language keyword needed for this purpose)

class C1 : C2

class

Class c1 extends c2

DEFINE CLASS MyClass AS ParentClass

Override a method or property

Overrides

(No language keyword required for this purpose)

(No language keyword required for this purpose except override for /clr compilations — see Derived Classes)

override

(No language keyword required for this purpose)

(No language keyword required for this purpose)

Declare a method that must be implemented in a deriving class

MustOverride

abstract

Put = 0 at the end of the declaration (pure virtual method)

abstract

abstract

(No language keyword required for this purpose)

Declare a method that cannot be overridden

NotOverridable (Methods are NotOverridable by default.)

final

sealed

sealed

final

n/a

Declare a virtual method or property, or property accessor

Overridable

(Methods are virtual by default)

virtual

virtual

(Methods are virtual by default)

n/a

Hide a base class member in a derived class

Shadowing

n/a

new (new slot in vtable)

new (C# Reference)

new Modifier

n/a

Declare a typesafe reference to a class method

Delegate

delegate

multicast

/** @delgate */

delegate

delegate

Use the name of the function without parentheses

n/a

Specify that a variable can contain an object whose events you wish to handle

WithEvents

n/a

n/a

(Write code - no specific keyword)

(Write code - no specific keyword)

EVENTHANDLER( ) NEW 

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

n/a

event += eventHandler;

n/a

BINDEVENTS( )

Evaluate an object expression once, in order to access multiple members

With objExpr <.member><.member> End With

n/a

n/a

using Statement (C# Reference)

with

WITH ... ENDWITH

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Structured exception handling

Try <attempt>

Catch

<handle errors>

Finally

<always execute>

End Try

Throw

try

catch

finally

throw

__try, __except

__finally

try, catch, finally

throw

try

catch

finally

throw

TRY

   [ tryCommands ]

[ CATCH [ To VarName ] [ WHEN IExpression ] ]

   [ catchCommands ] ]

[ THROW [ eUserExpression ] ]

[ EXIT ]

[ FINALLY

   [ finallyCommands ] ]

ENDTRY

C++ exception handling

n/a

n/a

try, catch, throw

n/a

n/a

n/a

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Decision structure (selection)

Select Case ..., Case, Case Else, End Select

switch

case

break

default

switch, case, default

goto

break

switch

case

default

goto

break

switch

case

break

CASE

ICASE

Decision structure (if ... then)

If ... Then, ElseIf ... Then, Else, End If

if

else

if, else

if, else

if

else

IF ... ENDIF

IIF( )

Loop structure (conditional)

While, Do [While, Until] ..., Loop [While, Until]

do

while

continue

do, while

continue

do

while

continue

do, while

break, continue

DO, WHILE (clauses)

Loop structure (iteration)

For ..., [Exit For] , Next

For Each ..., [Exit For] , Next

for

break

for

for

foreach

for (x=0;x<10;x++){...}

for (prop in obj) { print (obj[prop]);}

FOR (clauses)

FOR ... ENDFOR

Continue

NEXT

FOR EACH (clauses) ,FOR ... ENDFOR, Continue, Next

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Declare an array

Dim a() As Long

int[] x = new int[5];

int x[5];

int[] x = new int[5];

var x : int[]

var arr = Array()

DIMENSION

DECLARE

Initialize an array

Dim a() As Long = {3, 4, 5}

int[] x = {1,2,3,4,5};

int x[5]= {1,2,3,4,5};

int[] x = new int[5] {1, 2, 3, 4, 5};

var x : int[] = [1, 2, 3, 4, 5]

var arr = new Array(1, 2, 3, 4, 5)]

x[1] = 1

x[2] = 2

Reallocate array

Redim

n/a

n/a

n/a

arr.length=newSize (only for JScript arrays)10

DIMENSION

DECLARE

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Visible outside the project or assembly

Public

public

public

public

public

n/a

Invisible outside the assembly or within the package

Friend

(Omitting the scope keyword specifies "package scope")

private

internal

internal

n/a

Visible only within current or derived classes

Protected (Visual Basic)

n/a

n/a

Protected

n/a

n/a

Access is limited to the current assembly or types derived from the containing class.

Protected Friend

n/a

Type and Member Visibility

protected internal

Accessibility Levels

n/a

n/a

Visible only within the project (for nested classes, within the enclosing class)

Private

private

private

private

private

n/a

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Accessible outside class, project, and module

Public

public

public

public

public

(No language keyword required for this purpose)

Accessible outside the class, but within the project or package

Friend

(Omitting the scope keyword specifies "package scope")

public private:

internal

internal

n/a

Accessible only to current and derived classes

Protected

protected

protected

protected

protected

PROTECTED

Only accessible within class or module

Private

private

private

private

private

HIDDEN

Specify that a function or another class has access to private members of the declaring class

n/a

n/a

friend (Not allowed in C++)

friend

n/a

n/a

Protected inside the assembly and private to other assemblies

n/a

n/a

protected private

n/a

n/a

n/a

Access is limited to the current assembly or types derived from the containing class

Protected Friend

n/a

Type and Member Visibility

protected internal

Accessibility Levels

n/a

n/a

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Preserve procedure's local variables

Static 11

static

static

static (C# Reference)

n/a

n/a

Shared by all instances of a class

Shared

static

static

static

static

n/a

Purpose Visual Basic Visual J# C++ C# JScript Visual FoxPro

Comment code

'

Rem

//

/**

*/

/*

*/

//, /* */ for multiline comments

//, /* */ for multiline comments

/// for XML comments

//, /* */ for multiline comments

*

&&

NOTE

Case-sensitive?

No

Yes

Yes

Yes

Yes

No

Call Windows API

Declare <API>

Use J/Direct or Platform Invoke

n/a

use Platform Invoke

n/a

DECLARE - DLL

Declare and raise an event

Event

RaiseEvent

Use the java.awt.Event class

/** @event */

n/a

event

n/a

RAISEEVENT( ) function

Threading primitives

SyncLock

synchronized

n/a

lock

n/a

n/a

Go to (branch)

Goto

n/a

goto

goto

n/a

n/a

1 In Visual Basic, the only place where Static can be used by itself to declare a variable — for example, Static x As Long — is within a procedure.

2 In Visual Basic, procedures declared with the Sub keyword cannot return values. If a procedure is to return a value, you must declare it with the Function keyword.

3 In Visual Basic, Me is not resolved at compile time, so you can use it as the return value of a property or method.

4 In JScript, the substr function is still supported, but is no longer the preferred way to access characters within a string. The most efficient way to access a character from a particular location in a string is using brackets. For example, to access the tenth character in the string str, use str[10].

5 In Visual Basic, constructors for classes derived from .NET Framework System.Object are always named New.

6 In JScript, overloading is not allowed on constructors.

7 Typically, code in such a method frees system resources that would not automatically be freed by the garbage collector.

8 In C++, an abstract class includes at least one pure virtual member.

9 In JScript, there is no leading period such as you would use in Visual Basic. This feature can easily cause confusion, because variables can be mistaken for properties, and vice versa. Also note that the with statement produces slow code.

10 In JScript, this does not reallocate the array, and does not "grow" it either. JScript arrays (declared as type Array) are always sparse and dynamic. Native arrays (declared as System.Array or as type[]) are not dynamic.

11 In Visual Basic, static local variables of nonshared class methods are stored per class instance rather than sharing a single copy, as in other languages. When Static is used to declare a variable, the value of that variable is preserved even if the variable loses and then regains scope.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft