0% found this document useful (0 votes)
32 views

Section C#: (Automatic With Different Signature)

This document compares common C# and VB.NET syntax elements including: 1. Modifiers like public, private, protected, etc. and how they are defined in each language. 2. Basic syntax for classes, inheritance, interfaces, properties, methods, operators, enums, structs and more. 3. Differences in syntax for delegates, events, casting, attributes, operators, external functions and threading. 4. Notes on late binding, nullable types and other language differences.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Section C#: (Automatic With Different Signature)

This document compares common C# and VB.NET syntax elements including: 1. Modifiers like public, private, protected, etc. and how they are defined in each language. 2. Basic syntax for classes, inheritance, interfaces, properties, methods, operators, enums, structs and more. 3. Differences in syntax for delegates, events, casting, attributes, operators, external functions and threading. 4. Notes on late binding, nullable types and other language differences.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MODIFIERS

C# VB.NET
private Private
public Public
protected Protected
internal Friend
protected internal Protected Friend
static Shared
sealed (class) NotInheritable
sealed (method) NotOverridable
abstract (class) MustInherit
abstract (method) MustOverride
new Shadows
override Overrides
virtual Overridable
readonly ReadOnly
volatile [Unavailable]
[Automatic with Overloads
different signature]

Section C# VB.NET
Namespace using [Namespace]; Imports [Namespace]
Class
Simple define [Modifier] class [Name] [Modifier] Class [Name]
{ ...
... End Class
}
Inheritance : Inherits
Interface : [Class*], [Interface] Implements
Implementation
Static static MustInherit NotInheritable
Constructor
Declaration [Modifier] [class name] [Modifier] Sub New
([Parameters]) ([Parameters])
{ ...
... End Sub
}
Instance creation new [Type]([Parameters] New [Type]([Parameters

Method
[Modifier] void [Name]() [Modifier] Sub [Name]
Method { ([Parameters])
(procedure) ... ...
} End Sub
[Modifier] [Type] [Name] [Modifier] Function [Name]() As
Method ([Parameters]) [Type]
(function) { ...
... End Function
}
Parameter by value [Default] ByVal
Output Parameter out ByRef
Reference ref ByRef
parameter

Optional parameter [Unavailable] Optional

Undefined params ParamArray


parameter

Instance Access this Me

Base class access base MyClass

Base instance base MyBase


access

Return a value return Return

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

Set(ByVal Value As [Type])


...
End Set
End Property
Read only [Modifier] [Type] [Name] [Modifier] ReadOnly Property
{ [Name]() As [Type]
get Get
{ ...
} End Get
set End Property
{
}
}
Same as above [Modifier] WriteOnly Property
Write only [Name]() As [Type]
Set(ByVal Value As [Type])
...
End Set
End Property
[Modifier] [Type] Default [Modifier] Property
Indexer this([Parameters]) [Name]([Parameters]) As [Type]
{ Get
get ...
{ End Get
} Set(ByVal Value As [Type])
set ...
{ End Set
} End Property
}

Delegate
Procedure [Modifier] delegate void [Modifier] Sub Delegate [Name]
[Name] ([parameters]); ([Parameters])

Function [Modifier] delegate [Modifier] Function Delegate


[Return type] [Name] [Name] ([Parameters]) As
([parameters]); Return type

Access [] ()

Resize [Unavailable] ReDim


[Modifier] enum [Name] [Modifier] Enum [Name]
Enum { ...
} End Enum
[Modifier] struct [Name] [Modifier] Structure [Name]
Struct { ...
... End Structure
}
Interface [Modifier] interface [Modifier] Interface [Name]
[Name] ...
{ End Interface
}
EVENT
[Instance].[event]+= new [Modifier] WithEvents [field] As
Static [EventHandler] ( [method] ) [Type] [method] Handles [Field].
[Event]
[Instance] . [event] += new AddHandler [Instance] . [Event],
Dynamic [Add] [EventHandler] ( [method] ) AddressOf [Method]
[Instance] . [event] -= new RemoveHandler [Instance] .
Dynamic [EventHandler] ( [method] ) [event], AddressOf [method]
[Remove]
[Modifier] [Delegate type] [Modifier] Event [Delegate type]
Declaration event
[Event]([Parameters]) RaiseEvent [Event name]
Launch ([Parameters])

([Type name]) / as CType, CBool, CByte, CChar,


Cast CDate, CDbl,CDec, CInt, CLng,
CObj, CShort, CSng, CStr
typeof ( [Type name] ) GetType ( [Type name] )
Get Type
is TypeOf ([Instance]) Is [Type]
Is
Activate "Late Binding" [Unavailable] Option Strict Off

[ [Name] ([Parameters]) ] < [Name] ( [Parameters] ) > _


Attribute
public static [Result type] Public Shared Operator [symbol]
Operator operator [symbol] ( [parameters] )As [Result type]
Overloading ( [parameters] ) ...
{ End Operator
}
Extern,DllImport Declare,DllImport
External function
[Unavailable] With [Instance]
With ...
End With
lock ([Instance]) SyncLock [Instance]
Multithread { ...
protection ... End SyncLock
}
<struct>? Nullable(Of <struct>)
Nullable Type Ex: int? Ex: Nullable(Of Integer)

Document Source:

http://devolutions.net/articles/dot-net/C-Sharp-to-VB-Net.aspx

You might also like