Monday, May 28, 2012

C# Vs VB.net

1. 'Using' keyword of C# is used to release unused resources of an object.
Font myFont = new Font("Times New Roman", 8.0f);
            using (myFont) // not recommended
            {
                // use myFont
            }
After execution of inside statement of the braces resources used by myFont will be released. Class where you use 'Using' must to implement IDisposable interface.

2. C# is case sensitive.
3. Optional parameters to functions is not supported in C#.
4. C# doesn't have 'with' keyword that used to manipulate properties of an object in a single block.
With myObject
.Height = 20
.ForeColor = System.Drawing.Color.Green
.Text = "Hello..."
End With

5. Unstructured error handling not supported in C#. (On Error GOTO) is not supported in C#.
6. There is a concept of function Hiding in c# its called Hiding and in VB.Net its called Shadowing. We can have same name function in derived class that exist in base class that hides existence of that base class function in derived class.  In c# we mark it 'New' and in VB.Net we mark it 'Shadow'. Difference is that in C#, both the functions must have same signature while vb.net allow to change signature function.
7. In VB.Net we can call function by passing parameter with extra bracket that is not support by C#.
Dim y As Integer = 8
Dim z As Integer
z = Add(y) //This will set both Y and Z to 7.
z = Add((y)) //This will set Z to 7 but Value of Y will not be change, as we have included extra parentheses while calling.
             
The Subtract function:
Public Function Subtract(ByRef x As Integer) As Integer
x = x - 1
Return x
End Function

No comments:

Post a Comment

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...