Monday 12 November 2012

Csharp and VB.NET difference part-2: Keyword Differences:

Keyword Differences:


Declare a variable:


VB.NET:
Private, Public, Friend, Protected, Static1, Shared, Dim
C#:
declarators (keywords include user-defined types and built-in types)
Declare a named constant:
VB.NET:
Const
C#:
ConstCreate a new object:
VB.NET:
New, CreateObject()
C#:
new
Functionmethod does not return a value
VB.NET:
Sub
C#:
void
Overload a function or method (Visual Basic overload a procedure or method):
VB.NET:
Overloads
C#:
(No language keyword required for this purpose)
Refer to the current object
VB.NET:
Me
C#:
thisMake a nonvirtual call to a virtual method of the current object:
VB.NET:
MyClass
C#:
na











Retrieve character from a string:

VB.NET:
GetChar Function
C#:
[]
Declare a compound data type (Visual Basic Structure):
VB.NET:
Structure members End Structure
C#:
struct, class, interface
Initialize an object (constructors):
VB.NET:
Sub New()
C#:
Constructors, or system default type constructors
Terminate an object directly:
VB.NET:
na
C#:
na
Method called by the system just before garbage collection reclaims an object7:
VB.NET:
Finalize
C#:
destructor
Initialize a variable where it is declared:
VB.NET:
Dim x As Long = 5
Dim c As New Car(FuelTypeEnum.Gas)
initialize to a value
C#:
int x = 123;
or use default
constructor
int x = new int();
Take the address of a function
AddressOf (For class members, this operator returns a reference to a function in the form of a delegate instance) delegate
Declare that an object can be modified asynchronously
VB.NET:
na
C#:
volatile
Force explicit declaration of variables:
VB.NET:
Option Explicit
C#:
na. (All variables must be declared prior to use)
Test for an object variable that does not refer to an object
VB.NET:
obj = Nothing
C#:
obj == null
Value of an object variable that does not refer to an object
VB.NET:
Nothing
C#
null
Test for a database null expression
VB.NET:
IsDbNull
C#
na
Test whether a Variant variable has been initialized
VB.NET:
na
C#
na
Define a default property
VB.NET:
Default
C#
by using indexers
Refer to a base class
VB.NET:
MyBase
C#
base
Declare an interface
VB.NET:
Interface
C#
interface
Specify an interface to be implemented
VB.NET:
Implements (statement)
C#
class C1I1
Declare a class
VB.NET:
Class implementation
C#
class
Specify that a class can only be inherited. An instance of the class cannot be created.
VB.NET:
MustInherit
C#
abstract
Specify that a class cannot be inherited
VB.NET:
NotInheritable
C#
sealed
Declare an enumerated type
VB.NET:
Enum members End Enum
C#
enum
Declare a class constant
VB.NET:
Const
C#
const (Applied to a field declaration)
Derive a class from a base class
VB.NET:
Inherits C2
class C1C2
Override a method
VB.NET:
Overrides
C#
override
Declare a method that must be implemented in a deriving class
VB.NET:
MustOverride
C#
abstract
Declare a method that can't be overridden
VB.NET:
NotOverridable (Methods are not overridable by default.)
C#
sealed
Declare a virtual method, property (Visual Basic), or property accessor (C#, C++)
VB.NET:
Overridable
C#
virtual
Hide a base class member in a derived class
VB.NET:
Shadowing
C#
na
Declare a typesafe reference to a class method
VB.NET:
Delegate
C#
delegate
Specify that a variable can contain an object whose events you wish to handle
VB.NET:
WithEvents
(Write code - no specific keyword) 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.)
C#:
na
Evaluate an object expression once, in order to access multiple membersv
VB.NET:
With objExpr
.member
End With
C#:
na
Structured exception handling
VB.NET:
Try attempt
Catch
handle errors
Finally
always execute
End Try
C#:
try, catch, finally, throw
Decision structure (selection)
VB.NET:
Select Case ..., Case, Case Else, End Select
C#:
switch, case, default, goto, break
Decision structure (if ... then)
VB.NET:
If ... Then, ElseIf ... Then, Else, End If
C#:
if, else
Loop structure (conditional)
VB.NET:
While, Do [While, Until] ..., Loop [While, Until]
C#:
do, while, continue
Loop structure (iteration)
VB.NET:
For ..., [Exit For], Next
For Each ..., [Exit For,] Next
C#:
for, foreach
Declare an array
VB.NET:
Dim a() As Long
C#:
int[] x = new int[5];
Initialize an array
VB.NET:
Dim a() As Long = {3, 4, 5}
C#:
int[] x = new int[5] {1, 2, 3, 4, 5};
Reallocate array
VB.NET:
Redim
C#:
na
Visible outside the project or assembly
VB.NET:
Public
C#:
public
Invisible outside the assembly (C#Visual Basic) or within the package (Visual J#, JScript)
VB.NET:v Friend
C#:
internal
Visible only within the project (for nested classes, within the enclosing class)
VB.NET:
Private
C#:
private
Accessible outside class and project or module
VB.NET:
Public
C#:
public
Accessible outside the class, but within the project
VB.NET:
Friend
C#:
internal
Only accessible within class or module
VB.NET:
Private
C#:
private
Only accessible to current and derived classes
VB.NET:
Protected
C#:
protected
Preserve procedure's local variables
VB.NET:
Static
C#:
na
Shared by all instances of a class
VB.NET:
Shared
C#:
static
Comment code
VB.NET:
'
C#
Rem
VB.NET:
, for multi-line comments
C#
for XML comments
Case-sensitive
VB.NET:
No
C#:
Yes
Call Windows API
VB.NET:
Declare API
C#:
use Platform Invoke
Declare and raise an event
VB.NET:
Event, RaiseEvent
C#:
event
Threading primitives
VB.NET:
SyncLock
C#
Lock
VB.NET:
Go to
Goto
C#:
goto