Friday, 24 May 2013

Differences Between Microsoft Visual Basic .NET and C# .NET




The biggest differences between the languages fall into the following categories:

lCase sensitivity
lVariable declaration and assignment
lData types
lStatement termination
lStatement blocks
lUse of () vs. []
lOperators
lConditional statements
lError handling
lOverflow checking
lParameter passing
lLate binding
lHandling unmanaged code


lKeywords



1. Variable Declaration and Assignment

Visual Basic .NET


Visual C# .NET


Dim

i, j As Integer


int

i, j;


Dim

i As Integer = 7


int

i = 7;


Dim i(6) As Integer

or

Dim i() As Integer = New Integer(6) {}


int[]

i = new

int[6];


Dim con As SqlConnection


SqlConnection con;


Dim x As New Y("ABC")

or

Dim x As Y = New Y("ABC")


Y x = new Y("ABC");





2. Data Types


Visual Basic .NET
Visual C# .NET
.NET Framework
Boolean
bool
System.Boolean
Byte
byte
System.Byte
Short
short
System.Int16
Integer
int
System.Int32
Long
long
System.Int64
Single
float
System.Single
Double
double
System.Double
Decimal
decimal
System.Decimal
Date
System.DateTime
System.DateTime
String
string
System.String
Char
char
System.Char
Object
object
System.Object
n/a
sbyte
System.Sbyte
n/a
ushort
System.UInt16
n/a
uint
System.UInt32
n/a
ulong
System.UInt64




3. Statement Termination
 

Visual Basic .NET
Visual C# .NET

A = 5

B = 7 : C = 8

MySub (Arg1, _

            
Arg2, _

            
Arg3)


A = 5;

B = 7; C = 8;

MySub (Arg1,

            
Arg2,

            
Arg3);




4. Statement Blocks

Visual Basic .NET
Visual C# .NET

If A = 5 Then

 

DoSomething()

 

DoSomethingAgain()

End If


If (a == 5)

{

  

DoSomething();

  

DoSomethingAgain();

}

or

if (a == 5)

  

DoSomething();

  

DoSomethingAgain();

//This is not part of                     

          

 the if
statement.

5. Use of () vs. [ ]

Purpose
Visual Basic .NET
Visual C# .NET
Declare an array
Dim a() As Long
Dim a(3, 5) as Integer
int[] x = new int[5];
Initialize an array
Dim a() As Long = {3, 4, 5}
int[] x = new int[5] {1, 2, 3, 4, 5};
Reallocate array
Redim
n/a
Functions Arguments
X= A(5)
MySub (A, B, C)
MySub(A, B, C);
Property Indexes
Y = MyDataSet.Tables_       ("Author").Rows(5)._
Columns("AuthorID")
Y = MyDataSet.Tables["Author"].Rows[5].Columns["AuthorID"]



6. Operators

Operator
Visual Basic .NET        
Visual C# .NET
Additive
 
 
Addition
+
+
Subtraction
-
-
Multiplicative
 
 
Multiplication
*
*
Division
/
/
Integer division
\
/ (depending on the operands)
Modulus (division returning only the remainder)
Mod
%
Exponentiation
^
n/a
Logical
Visual Basic .NET
Visual C# .NET
Logical AND, OR
And
&&
Logical OR
Or
||
Conditional
 
 
Conditional
IIf
?:
Pointer to member
 
 
Pointer to member
n/a
. (Unsafe mode only)






7. Conditional Statements
Conditional Statement
Visual Basic .NET
Visual C# .NET
Decision structure (selection)

Select Case …, Case, Case Else, End Select
switch, case, default,
Decision structure (if … then)
If … Then, ElseIf … Then, Else, End If
if, else
Loop structure (conditional)
While… End While, Do [While, Until] …, Loop [While, Until]
do, while, continue
Loop structure (iteration)

For …, [Exit For,] Next
For Each …, [Exit For,] Next
for, foreach
Control flow statement
Exit, GoTo, Stop, End, Return,
break, continue, goto, return,
throw
8. Keywords


Purpose



Visual Basic .NET


Visual C# .NET



Object Oriented Programming









Indicates a class constructor



Public Class Class1


    Public Sub New(..)


     

MyBase.New


     …


    End Sub





End Class


Note: You have to call the base class constructor explicitly in Visual Basic .NET.



public class Class1


{


        public Class1(..)


        {


         …


        }


….


}


Note: The call to the base class constructor (base()) is generated automatically by the compiler in Visual C# .NET if you do not include constructor

initializers





Indicates a class destructor


Note: The Destructor or Finalize method is called by garbage collection.





Protected Overrides Sub Finalize()


  m_Gadget = Nothing


  m_Gear = Nothing


  MyBase.Finalize()


End Sub



public class Class1


{


        public ~Class1()


        {


         ….


        }


}



Declares a class



Class 



class



Indicates class inheritance



Public Class A


     Inherits B





End Class



public class A : B


{





}  



SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...