Introduction
Visual Basic .NET is an Object-Oriented programming language designed by Microsoft. With the word “Basic” being in the name of the language, you can already see that this is a language for beginners. Although the language is aimed at noobs and novices, you should not underestimate the power of the language itself. There are people who criticize VB.NET because of the simplicity of the syntax, but VB.NET has the ability to create very powerful and sophisticated applications. VB.NET is a great place to start because of how easy and straight forward it is. The syntax is easy and you will not find yourself writing hundreds of lines of code as there are many shortcuts that make coding so much easier in this language.If you have had any experience in computer programming, you should understand what a syntax is and the purpose of it. If not, let’s take a look at the VB.NET syntax. The purpose of typing code is to instruct the application what to do. It’s not as easy as typing “Hey application, multiply 5 by 8″ but it’s pretty darn close! If you wanted to tell your application to show a Message Box telling you that HowToStartProgramming.com is awesome, this would be the code you would use:
MessageBox.Show("HowToStartProgramming.com is awesome")Wow pretty easy right? I bet you thought that you would be typing 0′s and 1′s like in binary! Well now that you have looked at the syntax for VB.NET, you are ready to start your first tutorial. Please select the first tutorial from the list below and begin watching.
Complete Comparison for VB.NET and C#
Differences
- In C#, using keyword is used to release unmanaged resources. (Not available in VB.NET)
- Optional parameter is supported in VB.NET. (Not available in C#).
- Structure and unstructured error handling (On Error GoTo) is supported in VB.NET. (Unstructured error handling is not supported in C#).
- Event gets bind automatically in VB.Net.
- VB.NET is not case sensitive where C# is.
- Shadowing: – This is a VB.Net Concept by which you can provide a new implementation for the base class member without overriding the member. You can shadow a base class member in the derived class by using the keyword “Shadows”. The method signature, access level and return type of the shadowed member can be completely different than the base class member.
Hiding: – This is a C# Concept by which you can provide a new implementation for the base class member without overriding the member. You can hide a base class member in the derived class by using the keyword “new”. The method signature, access level and return type of the hidden member has to be same as the base class member. Comparing the two:- 1) The access level, signature and the return type can only be changed when you are shadowing with VB.NET. Hiding and overriding demands these parameters as same.
2) The difference lies when you call the derived class object with a base class variable. In class of overriding although you assign a derived class object to base class variable it will call the derived class function. In case of shadowing or hiding the base class function will be called. - Visual Basic .NET can also force parameters to be passed by value, regardless of how they are declared, by enclosing the parameters in extra parentheses. There is no way to achieve this thing in C#.
For Example:Dim y As Integer = 5
Dim z As Integer
z = Add(y) //This will set both Y and Z to 6.
z = Add((y)) //This will set Z to 6 but Value of Y will not be change, as we have included extra parenthese while calling.
The Add function:Public Function Add(ByRef x As Integer) As Integer
x = x + 1
Return x
End Function
Comparison
// Null-coalescing operatorx = y ?? 5; // if y != null then x = y, else x = 5
// Ternary/Conditional operatorgreeting = age < 20 ? "What's up?" : "Hello";
if (age < 20)
greeting = "What's up?";
else
greeting = "Hello";
// Multiple statements must be enclosed in {}if (x != 100 && y < 5) {
x *= 5;
y *= 2;
}
No need for _ or : since ; is used to terminate each statement.
if (x > 5)
x *= y;
else if (x == 5 || y % 2 == 0)
x += y;
else if (x < 10)
x -= y;
else
x /= y;
// Every case must end with break or goto case
switch (color) { // Must be integer or string
case "pink":
case "red": r++; break;
case "blue": b++; break; case "green": g++; break; default: other++; break; // break necessary on default}
VB.NET | Loops | C# |
Pre-test Loops: | |
While c < 10 c += 1 End While | Do Until c = 10 c += 1 Loop |
Do While c < 10 c += 1 Loop | For c = 2 To 10 Step 2 Console.WriteLine(c) Next |
Post-test Loops: | |
Do c += 1 Loop While c < 10 | Do c += 1 Loop Until c = 10 |
Reference Books
Download: Beginning ASP.NET 4.5 in VB
Download: Beginning ASP.NET 4.5: in C# and VB
No comments:
Post a Comment