Open Menu dzosoft
Close Menu dzosoft

   ALL ABOUT COMPUTER SCIENCE AND TECHNOLOGY


                             





Publish perfectly-optimized content in 1-click









 
 
 

Quick overview of the differences between C# and Visual Basic .NET

 
C# and Visual Basic .NET are two of the many programming languages ​​available for the .NET platform. The Common Language Runtime (CLR) of the .NET Framework constitutes, in fact, a common execution platform for a large number of languages, including C++, J#, Cobol.NET.
Rather than establishing which is the "best", it is interesting to understand the peculiarities of each language. We will focus on evaluating the most important differences.
At first glance it is clear that VB.NET is the preferred choice for those coming from previous versions of VB and ASP-VBScript, while C# is more appealing for those coming from experience with C++ and Java. The syntax of C# closely resembles that of Java, while that of VB.NET is an evolution of Visual Basic.
The most important difference in the transition from the old to the new is not so much the syntax but the feeling of newness in terms of the approach to object-oriented programming.
Those who are used to working in C++ or Java find an environment in which the concepts are similar if not completely overlapping. For example, in .NET as in Java everything is an object: any type of hybrid approach with C++ style structured programming is abandoned.
So those coming from the "old" ASP and VB find themselves faced with a language similar in some aspects of the basic syntax but with an approach to object-oriented programming that is common to the entire Framework and is more specific to Java and company.
C# is a new language, while VB .NET carries with it the legacy of all previous versions of Visual Basic (the syntax of VB .NET, although updated with object support, is practically the same as that of Visual Basic 4.0 , released way back in 1996).

A first obvious aspect is that the code written in VB .NET is longer than the equivalent in C#. Let's consider, for example, a function that takes two numbers as input and calculates their average:

//C#
public double GetAverage(double N1, double N2)
{
    return (N1 + N2) / 2;
}


'Visual Basic .NET
Public Function GetAverage(ByVal N1 As Double, ByVal N2 As Double) As Double

Return (N1 + N2) / 2 End Function


Another big difference, perhaps the most obvious, is that C# is case sensitive, that is, it is case sensitive, while VB is case insensitive: for C# the PersonName and PersonName variables are different, while for Visual Basic .NET they are the same .
Beyond the differences regarding the syntax, C# allows you to do things that cannot be done in VB .NET, and vice versa. For example, C#, showing its derivation from C++, allows you to use pointers, which VB .NET does not allow.
Some architectural differences have been filled with version 2.0 of the Framework, which also introduces operator overloading for Visual Basic .NET (another feature that C# took from C++) and the possibility of documenting the code written using the XML language. In fact, C# allows the documentation of classes using tags in the code in a way very similar to comments for JavaDocs.
VB .NET, in particular with the new version of the Framework, makes writing applications even simpler and faster: among the many examples that could be given in this regard, we mention the My namespace, which provides rapid access to a whole series of commonly used properties and methods, enabling more efficient development.
The information contained in the My namespace is also available from C#, but its presence in VB .NET makes carrying out some tasks much easier. For example, to download a file from the Internet, using Visual Basic .NET with the 2.0 Framework, all you need is one statement:
My.Computer.Network.DownloadFile("https://www.dzosoft.com/file.zip","C:/downloads")
In C# there is no My object and we would have to instantiate an object of the Network class to achieve the same effect.
Furthermore, the list of members that appears thanks to IntelliSense in VB .NET is divided into two tabs in which commonly used elements are highlighted, making it easier to select the desired item. In C# the member list is always displayed in its entirety.

 
Quick overview of the differences between C# and Visual Basic .NET
 
Visual Basic .NET IntelliSense

This quick overview of the differences between C# and Visual Basic .NET does not claim to be exhaustive

It might also interest you


C# Get Started

Using ChatGPT in C#

How to create a local MySQL connection in C#

How to execute a .NET Assembly inside a C# Program


Leave comment
          

Save nickname and email in this browser for the next time.



Loading...     
close publicity
Japanese ritual of tranquility and... slim figure!