Differences Between VB.NET& C# .NET-2
Keyword Differences
Purpose
VB.NET
C#
Declare a variable VB.NET
Private, Public, Friend, Protected, Static1, Shared, Dim
Declare a variable c#.NET
declarators (keywords include user-defined types and built-in types)
Declare a named constant vb.net
Const
Declare a named constant c#.net
const
Create a new object vb.net
New, CreateObject()
Create a new object c#.net
new
Function/method does not return a value vb.net
Sub
Function/method does not return a value c#.net
void
Overload a function or method (Visual Basic: overload a procedure or method) vb.net
Overloads
Overload a function or method (Visual Basic: overload a procedure or method) c#.net
(No language keyword required for this purpose)
Refer to the current object vb.net
Me
Refer to the current object c#.net
this
Make a nonvirtual call to a virtual method of the current object vb.net
MyClass
Make a nonvirtual call to a virtual method of the current object c#.net
n/a
Retrieve character from a string
vb.net>> GetChar Function
c#.net>> []
Declare a compound data type (Visual Basic: Structure)
vb.net>>Structure
c#.net>>struct, class, interface
Initialize an object (constructors)
vb.net>>Sub New()
c#.net>>Constructors, or system default type constructors
Terminate an object directly
vb.net>>n/a
c#.net>> n/a
Method called by the system just before garbage collection reclaims an object7
vb.net>> Finalize
c#.net>>destructor
Initialize a variable where it is declared
vb.net>>Dim x As Long = 5
c#.net>>Dim c As New _
Car(FuelTypeEnum.Gas)
// initialize to a value:
vb.net>>int x = 123;
// or use default
// constructor:
c#.net>>int x = new int();
Take the address of a function
vb.net>> AddressOf (For class members, this operator returns a reference to a function in the form of a delegate instance)
c#.net>>delegate
Declare that an object can be modified asynchronously
vb.net>>n/a
c#.net>> volatile
Force explicit declaration of variables
vb.net>>Option Explicit
c#.net>>n/a. (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#.net>>obj == null
Value of an object variable that does not refer to an object
vb.net>> Nothing
c#.net>> null
Test for a database null expression
vb.net>>IsDbNull
c#.net>>n/a
Test whether a Variant variable has been initialized
vb.net>>n/a
c#.net>>n/a
Define a default property
vb.net>>Default
c#.net>>by using indexers
Refer to a base class
vb.net>>MyBase
c#.net>>base
Declare an interface
vb.net>>Interface
c#.net>>interface
Specify an interface to be implemented
vb.net>>Implements (statement)
c#.net>>class C1 : I1
Declare a class
vb.net>>Class
c#.net>>class
Specify that a class can only be inherited. An instance of the class cannot be created.
vb.net>> MustInherit
c#.net>>abstract
Specify that a class cannot be inherited
vb.net>> NotInheritable
c#.net>>sealed
Declare an enumerated type
vb.net>> Enum
c#.net>>enum
Declare a class constant
vb.net>> Const
c#.net>>const (Applied to a field declaration)
Derive a class from a base class
vb.net>> Inherits C2
c#.net>>class C1 : C2
Override a method
vb.net>>Overrides
c#.net>> override
Declare a method that must be implemented in a deriving class
vb.net>> MustOverride
c#.net>> abstract
Declare a method that can't be overridden
vb.net>> NotOverridable (Methods are not overridable by default.)
c#.net>> sealed
Declare a virtual method, property (Visual Basic), or property accessor (C#, C++)
vb.net>>Overridable
c#.net>> virtual
Hide a base class member in a derived class
vb.net>> Shadowing
c#.net>> n/a
Declare a typesafe reference to a class method
vb.net>> Delegate
c#.net>>delegate
Specify that a variable can contain an object whose events you wish to handle
vb.net>> WithEvents
c#.net>> (Write code - no specific keyword)
Specify the events for which an event procedure will be called
vb.net>> Handles (Event procedures can still be associated with a WithEvents variable by naming pattern.)
c#.net>> n/a
Evaluate an object expression once, in order to access multiple members
vb.net>>With objExpr
<.member>
<.member>
End With
c#.net>>n/a
Structured exception handling
vb.net>>Try
Catch
Finally
End Try
c#.net>> try, catch, finally, throw
Decision structure (selection)
vb.net>> Select Case ..., Case, Case Else, End Select
c#.net>>switch, case, default, goto, break
Decision structure (if ... then)
vb.net>>If ... Then, ElseIf ... Then, Else, End If
c#.net>> if, else
Loop structure (conditional)
vb.net>> While, Do [While, Until] ..., Loop [While, Until]
c#.net>>do, while, continue
Loop structure (iteration)
vb.net>> For ..., [Exit For], Next
For Each ..., [Exit For,] Next
c#.net>> for, foreach
Declare an array
vb.net>>Dim a() As Long
c#.net>>int[] x = new int[5];
Initialize an array
vb.net>>Dim a() As Long = {3, 4, 5}
c#.net>>int[] x = new int[5] {
1, 2, 3, 4, 5};
Reallocate array
vb.net>> Redim
c#.net>> n/a
Visible outside the project or assembly
vb.net>>Public
c#.net>> public
Invisible outside the assembly (C#/Visual Basic) or within the package (Visual J#, JScript)
vb.net>> Friend
c#.net>> internal
Visible only within the project (for nested classes, within the enclosing class)
vb.net>>Private
c#.net>> private
Accessible outside class and project or module
vb.net>> Public
c#.net>>public
Accessible outside the class, but within the project
vb.net>> Friend
c#.net>>internal
Only accessible within class or module
vb.net>> Private
c#.net>> private
Only accessible to current and derived classes
vb.net>> Protected
c#.net>> protected
Preserve procedure's local variables
vb.net>> Static
c#.net>>n/a
Shared by all instances of a class
vb.net>> Shared
c#.net>> static
Comment code
vb.net>> '
Rem
c#.net>> //, /* */ for multi-line comments
/// for XML comments
Case-sensitive?
vb.net>> No
c#.net>> Yes
Call Windows API
vb.net>>Declare
c#.net>> use Platform Invoke
Declare and raise an event
vb.net>> Event, RaiseEvent
c#.net>>event
Threading primitives
vb.net>> SyncLock
c#.net>> lock
Go to
vb.net>> Goto
c#.net>> goto
Data types Differences
Purpose/Size
Decimal
vb.net>>Decimal
c#.net>> decimal
Date
vb.net>>Date
c#.net>> DateTime
(varies)
vb.net>> String
c#.net>> string
1 byte
vb.net>> Byte
c#.net>> byte
2 bytes
vb.net>>Boolean
c#.net>> bool
2 bytes
vb.net>> Short, Char (Unicode character)
c#.net>>short, char (Unicode character)
4 bytes
vb.net>> Integer
c#.net>> int
8 bytes
vb.net>> Long
c#.net>> long
4 bytes
vb.net>>Single
c#.net>> float
8 bytes
vb.net>> Double
c#.net>> double
Operators Differences
Purpose
Integer division
vb.net>>\
c#.net>> /
Modulus (division returning only the remainder)
vb.net>> Mod
c#.net>> %
Exponentiation
vb.net>>^
c#.net>> n/a
Integer division Assignment
vb.net>>\=
c#.net>> /=
Concatenate
vb.net>>&= NEW
c#.net>>+=
Modulus
vb.net>>n/a
c#.net>>%=
Bitwise-AND
vb.net>> n/a
c#.net>> &=
Bitwise-exclusive-OR
vb.net>> n/a
c#.net>>^=
Bitwise-inclusive-OR
vb.net>>n/a
c#.net>> |=
Equal
vb.net>> =
c#.net>> ==
Not equal
vb.net>><>
c#.net>> !=
Compare two object reference variables
vb.net>> Is
c#.net>>==
Compare object reference type
vb.net>> TypeOf x Is Class1
c#.net>> x is Class1
Concatenate strings
vb.net>> &
c#.net>>+
Shortcircuited Boolean AND
vb.net>>AndAlso
c#.net>>&&
Shortcircuited Boolean OR
vb.net>>OrElse
c#.net>> ||
Scope resolution
vb.net>> .
c#.net>> . and base
Array element
vb.net>> ()
c#.net>> [ ]
Type cast
vb.net>> Cint, CDbl, ..., CType
c#.net>> (type)
Postfix increment
vb.net>> n/a
c#.net>> ++
Postfix decrement
vb.net>>n/a
c#.net>> --
Indirection
vb.net>> n/a
c#.net>> * (unsafe mode only)
Address of
vb.net>> AddressOf
c#.net>> & (unsafe mode only; also see fixed)
Logical-NOT
vb.net>> Not
c#.net>> !
One's complement
vb.net>> Not
c#.net>>~
Prefix increment
vb.net>> n/a
c#.net>>++
Prefix decrement
vb.net>> n/a
c#.net>>--
Size of type
vb.net>> n/a
c#.net>>sizeof
Bitwise-AND
vb.net>>And
c#.net>> &
Bitwise-exclusive-OR
vb.net>> Xor
c#.net>>^
Bitwise-inclusive-OR
vb.net>>Or
c#.net>> |
Logical-AND
vb.net>> And
c#.net>>&&
Logical-OR
vb.net>> Or
c#.net>> ||
Conditional
vb.net>>If Function ()
c#.net>> ?:
Pointer to member
vb.net>>n/a
c#.net>> . (Unsafe mode only)
Programming Difference
<<<<PREVOIUS
NEXT>>>>
No comments:
Post a Comment