Sei sulla pagina 1di 6

Language Differences

VB.NET C# Comments

Specifies that a class


NotInheritable sealed cannot be used as a
base class, i.e. that it
cannot be inherited.

Specifies that a
NotOverridable sealed method cannot be
overriden.

Specifies that a class


can only be inherited
MustInherit abstract (an instance of the
class cannot be
created).

Specified that a
MustOverride abstract method must be
implemented in a
derived class.

Specifies that a
Overridable virtual member can be
overriden.

Specifies that a
member is shared by
all instances of a
Shared static class. An instance of
the class is not
required to call the
member.

Specifies that a local


variable's value is
Static no equivalent
preserved between
calls.

Class/member is
Public public visible outside of
project or assembly.

Class/member is
Friend internal invisible outside of
the assembly.

Class/member is
Private private visible only within
the project.

Specifies that a
Overloads not required member is
overloading another
member.
Specifies that a
Overrides override member is overriding
another member.

Specifies that the


Implements I1 class C1:I1 class (C1)
implements the
interface I1.

Specifies that the


Inherits C2 class C1:C2 class (C1) inherits
class C2.

Specifies that the


Implements I1 class (C1)
class C1:C2,I1 implements the
Inherits C2 interface I1 and
inherits class C2.

Shadows new

Method called by
system just before
Finalize ~C1 (destructor) garbage collection
reclaims object. C1 is
classname.

Constructor method,
New C1 called when object is
created. C1 is
classname.

Declares variable x
Dim x as Int32 Int32 x as type
System.Int32.

Dim t1 As New
SomeType()
Try
t1.SomeMethod()
Finally
using(SomeType t1 = new
If (t1 Is Nothing)
SomeType())
Then
{
If TypeOf t1 Is
t1.SomeMethod;
IDisposable Then
}
CType(t1,
IDisposable).Dispose()
End If
End If
End Try

Allows methods to be
Imports using called without fully
qualifying with
Namespace name.

<> [] Specifies
parameters.
Function x as Int32 Int32 x Specifies return
values (Int32 and
Sub y void y none).

Line continuation
_ ; character in VB, end
of line character in
C#.

AndAlso &&
Short circuit versions
of And and Or.
OrElse ||

not supported << >> Shift operators.

X+=1 (x=x+1)
x++
Short cut
X-=1 (x=x-1)
incrementers.
x--
also *=, /=, ^= etc..

Dim x(4) as Int32 Int32[] x = new Int32[4]; Differences in array


declarations and the
number of elements
= 5 items (0 to 4) = 4 items (0 to 3) created.

Dim x as Int32 Int32 x = 0 x initialised as zero


automatically in VB.

Redimensions an
ReDim Preserve no equivalent
array.

Specifies and
Optional need to overload sub instead
optional parameter.

switch(I)
Select Case x
{
Case True
case 1:break;
Case Else
default:break;
End Select
};

ByVal not required Passing parameters


by value and by
ByRef ref reference.

Me this Refer to the current


object.

MyBase base Refer to the base


calss.

Make a non-virtual
call to a virtual
MyClass no eqivalent
method of the
current object.

Const const Declare a constant.


readonly

Enum enum Declare an


enumerator.

Structure struct Declare a structure.

Declare that an
no equivalent volatile object can be
modifed
asynchronously.

Test for an object


obj = Nothing obj == null variable that does
not point to
anything.

Specify that all


Option Explicit on by default and not changable variables must be
declared.

Test for a database


IsDBNull no equivalent
Null.

Specify default
Default must use indexer
method of a class.

Declare a variable
WithEvents no equivalent whose events you
wish to handle.

Specify that the


Handles no equivalent method is an event
sink.

Try
try{}
Catch
catch{} Structured exception
Finally
finally{} handling
End Try

If Number < 10 Then


Digits = 1
ElseIf Number < 100 if (x > 10)
Then {
' Condition evaluates if (y > 20)
to True so the next Console.Write("Statement_1"); Conditions.
statement is executed. }
Digits = 2 else
Else Console.Write("Statement_2");
Digits = 3
End If

For I = 1 To 10 for (int i = 1; i <= 5; i++) Iterations.


For J = 1 To 10 Console.WriteLine(i);
For K = 1 To 10
' Statements to
operate with current
values of I, J, and K.
Next K
Next J
Next I

REM /* ... */
Comment lines
' //

not supported /// XML comment lines

Dim x As String =
string x = "hello";
"Hello"
char y; Retrieve a character
Dim y As Char = from a String.
y = x[1];
GetChar(x, 1)

AddressOf delegate Use the address of a


method.

Evaluate an object
With ... End With no equivalent one and use many
times.

Dim a() as Long = int[] x = new int[4]


{1,2,3} {1,2,3,4}; Initialise an array.

Event
event Declare and raise an
event.
RaiseEvent

SyncLock lock Threading primitives.

Defaults to Private Scope Defaults to Private Scope

- Variable in class - Variable in class


- Variable in struct
- Method in class
Defaults to Public Scope
- Method in struct

- Variable in Structure
Defaults to Public Scope
- Structure
- Class
- Method in Class - struct
- Method in Structure - class

public void ShowWord() An output parameter


{ is a parameter that is
string Word; passed from a called
myWord(out Word); method to the
Console.Writeline("Word is " method that called it,
+ Word); that is, the
no equivalent } reverse direction.
public void myWord (out Output parameters
string Word) are useful if you
{ want a method to
Word = "Hello World";
return more than a
}
single value.
see @

Visual Basic .NET


Help.ShowHelp(MyForm, @
"C:\myHelpFile.htm")
Visual C#
Help.ShowHelp(MyForm,
@"C:\myHelpFile.htm");

Potrebbero piacerti anche