Académique Documents
Professionnel Documents
Culture Documents
VB.NET C#
Support for optional parameters - very handy for XML documentation generated from source
some COM interoperability. code comments. (This is coming in VB.NET
Support for late binding with Option Strict off - type with Whidbey (the code name for the next
safety at compile time goes out of the window, but version of Visual Studio and .NET), and there
legacy libraries which don't have strongly typed are tools which will do it with existing VB.NET
interfaces become easier to use. code already.)
Support for named indexers. Operator overloading - again, coming to
Various legacy VB functions (provided in VB.NET in Whidbey.
the Microsoft.VisualBasic namespace, and can Language support for unsigned types (you can
be used by other languages with a reference to use them from VB.NET, but they aren't in the
the Microsoft.VisualBasic.dll). Many of these can be language itself). Again, support for these is
harmful to performance if used unwisely, however, coming to VB.NET in Whidbey.
and many people believe they should be avoided for The using statement, which makes
the most part. unmanaged resource disposal simple.
The with construct: it's a matter of debate as to Explicit interface implementation, where an
whether this is an advantage or not, but it's certainly ainterface which is already implemented in a
difference. base class can be re-implemented separately
Simpler (in expression - perhaps more complicated in in a derived class. Arguably this makes the
understanding) event handling, where a method can class harder to understand, in the same way
declare that it handles an event, rather than the that member hiding normally does.
handler having to be set up in code. Unsafe code. This allows pointer arithmetic etc,
The ability to implement interfaces with methods of and can improve performance in some
different names. (Arguably this makes it harder to find situations. However, it is not to be used lightly,
the implementation of an interface, however.) as a lot of the normal safety of C# is lost (as
Catch ... When ... clauses, which allow exceptions to the name implies). Note that unsafe code is
be filtered based on runtime expressions rather than still managed code, i.e., it is compiled to IL,
just by type. JITted, and run within the CLR.
The VB.NET parts of Visual Studio .NET compiles your
code in the background. While this is considered as
an advantage for small projects, people creating very
large projects have found that the IDE slows down
considerably as the project gets larger.
Keyword Differences
Purpose VB.NET C#
Declare a Private, Public, Friend, Protected, Static1, Sh declarators (keywords
variable ared, Dim include user-defined types and
built-in types)
Declare a Const const
named
constant
Create a new New, CreateObject() new
object
Function/met Sub void
hod does not
return a value
Overload a Overloads (No language keyword required
function or for this purpose)
method
(Visual Basic:
overload a
procedure or
method)
Refer to the Me this
current object
Make a MyClass n/a
nonvirtual call
to a virtual
method of the
current object
Retrieve GetChar Function []
character from
a string
Declare a Structure <members> End Structure struct, class, interface
compound
data type
(Visual Basic:
Structure)
Initialize an Sub New() Constructors, or system default
object type constructors
(constructors)
Terminate an n/a n/a
object directly
Method called Finalize destructor
by the system
just before
garbage
collection
reclaims an
object7
Initialize a Hide Copy Code Hide Copy Code
variable where Dim x As Long = 5 // initialize to a value:
it is declared int x = 123;
Hide Copy Code// or use default
Dim c As New _ // constructor:
Car(FuelTypeEnum.Gas) int x = new int();
Take the AddressOf (For class members, this operator returns delegate
address of a a reference to a function in the form of a delegate
function instance)
Declare that n/a volatile
an object can
be modified
asynchronousl
y
Force explicit Option Explicit n/a. (All variables must be
declaration of declared prior to use)
variables
Test for an obj = Nothing obj == null
object variable
that does not
refer to an
object
Value of an Nothing null
object variable
that does not
refer to an
object
Test for a IsDbNull n/a
database null
expression
Test whether an/a n/a
Variant
variable has
been
initialized
Define a Default by using indexers
default
property
Refer to a MyBase base
base class
Declare an Interface interface
interface
Specify an Implements (statement) class C1 : I1
interface to be
implemented
Declare a classClass <implementation> class
Specify that a MustInherit abstract
class can only
be inherited.
An instance of
the class
cannot be
created.
Specify that a NotInheritable sealed
class cannot
be inherited
Declare an Enum <members> End Enum enum
enumerated
type
Declare a classConst const (Applied to a field
constant declaration)
Derive a class Inherits C2 class C1 : C2
from a base
class
Override a Overrides override
method
Declare a MustOverride abstract
method that
must be
implemented
in a deriving
class
Declare a NotOverridable (Methods are sealed
method that not overridable by default.)
can't be
overridden
Declare a Overridable virtual
virtual
method,
property
(Visual Basic),
or property
accessor (C#,
C++)
Hide a base Shadowing n/a
class member
in a derived
class
Declare a Delegate delegate
typesafe
reference to a
class method
Specify that a WithEvents (Write code - no specific
variable can keyword)
contain an
object whose
events you
wish to handle
Specify the Handles (Event procedures can still be associated n/a
events for with a WithEventsvariable by naming pattern.)
which an
event
procedure will
be called
Evaluate an Hide Copy Coden/a
object With objExpr
expression <.member>
<.member>
once, in order End With
to access
multiple
members
Structured Hide Copy Codetry, catch, finally, throw
exception Try <attempt>
handling Catch
<handle errors>
Finally
<always execute>
End Try
Decision Select Case ..., Case, Case Else, End Select switch, case, default, goto,
structure break
(selection)
Decision If ... Then, ElseIf ... Then, Else, End If if, else
structure (if ...
then)
Loop structureWhile, Do [While, Until] ..., Loop [While, do, while, continue
(conditional) Until]
Loop structureFor ..., [Exit For], Next<BR>For Each ..., for, foreach
(iteration) [Exit For,] Next
Declare an Hide Copy Code Hide Copy Code
array Dim a() As Long int[] x = new int[5];
Operators Differences
Purpose VB.NET C#
Integer division \ /
Modulus (division returning Mod %
only the remainder)
Exponentiation ^ n/a
Integer division Assignment \= /=
Concatenate &= NEW +=
Modulus n/a %=
Bitwise-AND n/a &=
Bitwise-exclusive-OR n/a ^=
Bitwise-inclusive-OR n/a |=
Equal = ==
Not equal <> !=
Compare two object Is ==
reference variables
Compare object reference TypeOf x Is Class1 x is Class1
type
Concatenate strings & +
Shortcircuited Boolean AND AndAlso &&
Shortcircuited Boolean OR OrElse ||
Scope resolution . . and base
Array element () [ ]
Type cast Cint, CDbl, ..., CType (type)
Postfix increment n/a ++
Postfix decrement n/a --
Indirection n/a * (unsafe mode only)
Address of AddressOf & (unsafe mode only; also see fixed)
Logical-NOT Not !
One's complement Not ~
Prefix increment n/a ++
Prefix decrement n/a --
Size of type n/a sizeof
Bitwise-AND And &
Bitwise-exclusive-OR Xor ^
Bitwise-inclusive-OR Or |
Logical-AND And &&
Logical-OR Or ||
Conditional If Function () ?:
Pointer to member n/a . (Unsafe mode only)
Programming Difference
Purpose VB.NET C#
Declaring Hide Copy Code Hide Copy Code
Variables Dim x As Integer int x;
Public x As Integer = 10 int x = 10;
Hiding Base Hide Shrink Copy Code Hide Shrink Copy Code
Class Public Class BaseCls public class BaseCls
Members ' The element to be shadowed {
Public Z As Integer = 100 // The element to be hidden
public Sub Test() public int Z = 100;
System.Console.WriteLine( _ public void Test()
"Test in BaseCls") {
End Sub System.Console.WriteLine(
End Class "Test in BaseCls");
}
Public Class DervCls }
Inherits BaseCls
' The shadowing element. public class DervCls : BaseCls
Public Shadows Z As String = "*" {
public Shadows Sub Test() // The hiding element
System.Console.WriteLine( _ public new string Z = "*";
"Test in DervCls") public new void Test()
End Sub {
End Class System.Console.WriteLine(
"Test in DervCls");
Public Class UseClasses }
' DervCls widens to BaseCls. }
Dim BObj As BaseCls =
New DervCls() public class UseClasses
' Access through derived {
' class. // DervCls widens to BaseCls
Dim DObj As DervCls = BaseCls BObj = new DervCls();
New DervCls() // Access through derived
//class
Public Sub ShowZ() DervCls DObj = new DervCls();
System.Console.WriteLine( _ public void ShowZ()
"Accessed through base "&_ {
"class: " & BObj.Z) System.Console.WriteLine(
System.Console.WriteLine(_ "Accessed through " +
"Accessed through derived "&_ "base class: {0}",
"class: " & DObj.Z) BObj.Z);
BObj.Test() System.Console.WriteLine(
DObj.Test() "Accessed through" +
End Sub " derived class:{0}",
End Class DObj.Z);
BObj.Test();
DObj.Test();
}
}