services   articles   contacts  
 
C# to VB.NET
    Functionalities
    C#
    VB.Net
    Identifier
    Case sensitive Not case sensitive
         
    Instruction end
    ; [CrLf]
     
       
    Multi line command
    [CrLf] _
     
       
    Comment
       
    Line
    //
    '
    REM
    Section
    /* */ [Unavailable]
     
       
    String
    " "
     
       
    Char
    ' '
     
       
    Null value
    null Nothing
         
    Get char from string
    [] GetChar([String], [Index])
         
    CrLf
    "\r\n" vbCrLf
         
    Operators
       
      & And
      && AndAlso
      | Or
      || OrElse
      == =
      + +
      - -
      * *
      / /
      != <>
      > >
      < <
      >= >=
      <= <=
      ! Not
      % Mod
      ++ [Unavailable]
      -- [Unavailable]
      += +=
      -= -=
         
    Modifiers
       
      private Private
      public Public
      protected Protected
      internal Friend
      protected internal Protected Friend
      static Shared
      [Automatic with different signature] Overloads
      sealed (class) NotInheritable
      sealed (method) NotOverridable
      abstract (class) MustInherit
      abstract (method) MustOverride
      new Shadows
      override Overrides
      virtual Overridable
      readonly ReadOnly
      volatile [Unavailable]
         
    Namespace
       
    Uses
    using [Namespace]; Imports [Namespace]
    Define

    namespace [name] {
    .
    }
    Namespace [name]
    .
    End Namespace
     
       
    Class
       
    Simple define

    [Modifier] class [Name] {
    ...
    }
    [Modifier] Class [Name]
    ...
    End Class
    Inheritance
    : Inherits
    Interface implementation
    : [Class*], [Interface] Implements
    Static
    static MustInherit NotInheritable
     
       
    Constructor

       
    Declaration

    [Modifier] [class name] ([Parameters]) {
    ...
    }
    [Modifier] Sub New ([Parameters])
    ...
    End Sub
    Instance creation
    new [Type]([Parameters] New [Type]([Parameters])
     
       
    Variable
       
    Simple
    [Type] [Name]; Dim [Name] As [Type]
    With initialization
    [Type] [Name] = [Value]; Dim [Name] As [Type] = [Value]
     
       
    Method
       
    Method (procedure)

    [Modifier] void [Name]() {
    ...
    }
    [Modifier] Sub [Name]([Parameters])
    ...
    End Sub
    Method (function)

    [Modifier] [Type] [Name]([Parameters]) {
    ...
    }
    [Modifier] Function [Name]() As [Type]
    ...
    End Function
    Parameter by value
    [Default] ByVal
    Output parameter
    out ByRef
    Reference parameter
    ref ByRef
    Optional parameter
    [Unavailable] Optional
    Undefined parameter
    params ParamArray
    Instance access
    this Me
    Base class access
    base MyClass
    Base instance access
    base MyBase
    Return a value
    return Return
     
       
    Property
       
    Read / Write






    [Modifier] [Type] [Name] {
    get {...}
    set {...}
    }



    [Modifier] Property [Name]() As [Type]
    Get
    ...
    End Get
    Set(ByVal Value As [Type])
    ...
    End Set
    End Property
    Read only



    [Modifier] [Type] [Name] {
    get {...}
    set {...}
    }
    [Modifier] ReadOnly Property [Name]() As [Type]
    Get
    ...
    End Get
    End Property
    Write only


    [Modifier] [Type] [Name] {
    get {...}
    set {...}
    }
    [Modifier] WriteOnly Property [Name]() As [Type]
    Set(ByVal Value As [Type])
    ...
    End Set
    End Property
    Indexer







    [Modifier] [Type] this([Parameters]) {
    get {...}
    set {...}
    }




    Default [Modifier] Property [Name]([Parameters]) As [Type]
    Get
    ...
    End Get
    Set(ByVal Value As [Type])
    ...
    End Set
    End Property
     
       
    Delegate
       
    Procedure
    [Modifier] delegate void [Name] ([parameters]); [Modifier] Sub Delegate [Name] ([Parameters])
    Function
    [Modifier] delegate [Return type] [Name] ([parameters]); [Modifier] Function Delegate [Name] ([Parameters]) As Return type]
     
       
    Event
       
    Static

    [Instance].[event]+= new [EventHandler] ( [method] )
    [Modifier] WithEvents [field] As [Type] [method] Handles [Field].[Event]
    Dynamic (add)
    [Instance] . [event] += new [EventHandler] ( [method] ) AddHandler [Instance] . [Event], AddressOf [Method]
    Dynamic (remove)
    [Instance] . [event] -= new [EventHandler] ( [method] ) RemoveHandler [Instance] . [event], AddressOf [method]
    Declaration
    [Modifier] [Delegate type] event [Modifier] Event [Delegate type]
    Launch
    [Event]([Parameters]) RaiseEvent [Event name]([Parameters])
         
    Array
       
    Create






    Samples :
    int[] t0;
    int[4] t1;
    int[] t2;
    int[] t3 = new int[3];
    int[] t4 = {1, 2, 3};
    int[] t4 = {1, 2, 3}
    Samples :
    Dim t0() As Integer
    Dim t1(3) As Integer
    Dim t2 As Integer()
    Dim t3 As Integer() = New Integer(2) {} 'Array with 3 items
    Dim t4 As Integer() = New Integer() {1, 2, 3}
    Dim t5 As Integer() = New Integer(2) {1, 2, 3}
    Access
    [] ()
    Resize
    [Unavailable] ReDim
     
       
    Enum

    [Modifier] enum [Name] {
    ...
    }

    [Modifier] Enum [Name]
    ...
    End Enum
     
       
    Struct
    [Modifier] struct [Name] {
    ...
    }
    [Modifier] Structure [Name]
    ...
    End Structure
     
       
    Interface

    [Modifier] interface [Name] {
    ...
    }
    [Modifier] Interface [Name]
    ...
    End Interface
     
       
    Cast

    ([Type name]) / as

    CType, CBool, CByte, CChar, CDate,
    CDbl, CDec, CInt, CLng, CObj, CShort,
    CSng, CStr
         
    Get the type
    typeof ( [Type name] ) GetType ( [Type name] )
         
    Is
    is TypeOf ([Instance]) Is [Type]
     
       
    Const
    [Modifier] const [Type ][Name] = [Value] [Modifier] Const [Name] As [Type] = [Value]
         
    If

    if ([Bool expression]) {
    ...
    }
    If [Bool expression]
    ...
    End If
         
    For

    for( int I = [i]; I < [ii + 1]; i+=[iii]) {
    ...
    }
    For i = [i] To [ii] Step [iii]
    ...
    Next i
     
       
    For Each

    foreach ([Type] [Name] in [Collection Instance]) {
    ...
    }
    For Each [Name] As [Type] In [Collection instance]
    ...
    Next
         
    Switch














    Samples:
    switch (Welcome) {
    case "Hello" :
    return "Hello";
    case "Hi" :
    break;
    case "Goofbye" :
    default :
    return "Goodbye";
    }





    Samples:
    Select Case counter
    Case 1 ' counter egals 1.
    Return counter * 0.1
    Case 2, 3 ' counter equals 2 ou 3.
    Return counter * 0.09
    Case 5 To 7 ' counter equals 5, 6, ou 7.
    Return counter * 0.07
    Case 4, 8 To 10 ' counter equals 4, 8, 9, ou 10.
    Return counter * 0.05
    Case Is < 15 ' counter equals 0, 11, 12, 13, ou 14.
    Return 100
    Case Else
    Return 0
    End Select
     
       
    While

    while ( [Bool expression] ) {
    ...
    }
    While [Bool expression ]
    ...
    End While
     
       
    Try





    try {
    ...
    } catch ([Exception type] [Name]) {
    ...
    } finally {
    ...
    }
    Try
    ...
    Catch [Name] As [Exception type]
    ...
    Finally
    ...
    End Try
     
       
    Throw exception
    throw new [Exception type]([Parameters])
    Throw New [Exception type]([Parameters])
     
       
    Activate "Late Binding"
    [Unavailable] Option Strict Off
     
       
    Attribute
    [ [Name] ([Parameters]) ] < [Name] ( [Parameters] ) > _
     
       
    Operator overloading


    public static [Result type ] operator [symbol]
    ( [parameters] )
    {
    ...
    }
    Public Shared Operator [symbol] ( [parameters] ) As [Result type]
    ...
    End Operator

     
       
    Cast operator overloading

    public static [implicit or explicit] operator
    [Result type] ( [Original type )
    {
    ...
    }

    Public Shared [Narrowing | Widening] Operator CType(ByVal Param1 As [Type1]) As [Result type]
    ...
    End Operator


     
       
    External function
    extern
    DllImport
    Declare
    DllImport
     
       
    With

    [Unavailable]

    With [Instance]
    ...
    End With
     
       
    Multithread protection

    lock ([Instance]) {
    ...
    }
    SyncLock [Instance]
    ...
    End SyncLock
     
       
    Nullable type

    <struct>?
    Ex: int?
    Nullable(Of <struct>)
    Ex: Nullable(Of Integer)

 
Copyright ©2006, Devolutions inc.
 
Français