C# is a high-level programming language that is safe, stable, simple, and elegant. It has many similarities with Visual Basic, but also has many differences. Our blog today is based on the principle of learning C# and focuses on the similarities and differences between C# and Visual Basic. It is elaborated from several aspects respectively. Due to space limitations, we may divide it into several parts and present it in the form of several blog posts. I hope everyone will pay more attention and provide more valuable opinions, so that we can make progress together! Let’s get to the point-
C#, like Visual Basic, is an object-oriented visual programming language. C# has become the preferred language for .NET development due to its powerful operating capabilities, elegant grammatical style, innovative language features and convenient support for component-oriented programming. Based on a better and more comprehensive study of C#, we equate C# with the Visual Basic language and compare the differences and similarities between the two. Production: If you want to speak a language, the first thing you cannot let go of is its production. Although in terms of programming, the creation of a language is not the highlight of the language, it is also a part that cannot be ignored. Tracing its roots and its development will help us better understand, learn, and master this language. Here we briefly introduce it. Let’s start with Visual Basic, referred to as VB, which is a software development tool based on the Windows operating system launched by Microsoft in the United States. It is a powerful high-level programming language. It can be said that Visual Basic is the most basic language among all programming languages, and many people may dismiss its learning. However, precisely because of the foundation, its learning will lay a good foundation for learning other programming languages in the future. You will find that it will not be so difficult when you come into contact with a new programming language. (I will write a special article later to introduce the importance of basic learning of VB for learning other programming languages, so I won’t go into details here) Let’s talk about C# again. C# is pronounced C Sharp. It is a new programming language released by Microsoft in 2000. The programming language, mainly developed by Anders Hejlsberg, is the first component-oriented programming language. It is derived from C and C++, and has some powerful functions based on C and C++, while also removing some of their complex features, integrating the simple visual operations of VB and the high operating efficiency of C++. For example: This is a program that displays Welcome to the C# learning!. The following shows the code and interface display of this same program in C# and Visual Basic. Let’s analyze them one by one. This is the running form interface of C# [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My example Hello_World { class PRogram { static void Main(string[] args) { Console.WriteLine("Welcome to the C# learning!!!"); } } } This is the code part of C# to implement the above interface. This is the running form interface of VB [vb] Private Sub Form_Load() Me.AutoRedraw = True FontSize = 18 FontBold = True Print "Welcome to the C# learning!!!" End Sub [vb] Private Sub Form_Click() FontSize = 18 FontBold = True Print "Welcome to the C# learning!!" !" End Sub This is the code part of VB that implements the above interface. Anyone who has been in contact with VB knows that there are two different ways to implement the above interface. One uses the Click event and the other uses the Form_Load event. Through the comparison of the above pictures, we can clearly see the difference between C# and VB. The example code above is very simple, so the effect may not be particularly obvious. Comparing C# and VB, in fact, implementing this example is just a matter of code. You can add a control in VB. Take adding a Label control as an example. The code can be written directly as [vb] <span > Label1.Caption = "Welcome to the C# learning!!!" </span> The code in C#, study The root of it is actually just one sentence. Take this line of code separately, as follows: [csharp] <span > Console.WriteLine("Welcome to the C# learning!!!");</span> Okay, now, compare this line of code in VB with the code in C#. You will find that the two are really similar, but different. Let’s look at the VB code first. The code means: the Caption of Label1 (this control) is Welcome to the C# learning!!!; the C# code means: the WriteLine (Console class) of Console (Console class). method) displays the text line "Welcome to the C# learning!!!". Both display text, but the expression methods are completely different: there is an equal sign in VB, but in C# the medium sign means assignment, and the double equal sign == has the same meaning as = in VB; and in C# the WriteLine method The line of text to be represented is enclosed in parentheses, and note that there is a semicolon at the end of the line of code, that is;. After a lot of exposure to C#, you will find that in C# code, many codes have a semicolon -;, such as the following code: [csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace My example 1 { class Program { static void Main(string[] args) { for (int i = 0; i < 10; i++) { Console.Write("Please enter a statement (enter end):"); string s = Console.ReadLine(); if (s == "end") { break; } Console.WriteLine("The word you entered:" " + s); } } } } When you come into contact with C# a lot in the future, you will find that a semicolon is added after a line of code. The C# code language block is enclosed with { }, and there is no semicolon at the end. As you learn more about C# and the amount of code increases, you will gradually figure out the rules. Annotation method: [vb] [csharp] //This is C# programming code using System; //Import System namespace using System.Collections.Generic; using System.Linq; using System.Text; namespace My example Hello_World //Statement Namespace My example Hello_World { class Program //Declare Program class { static void Main(string[] args) //Program entry point, the return type of Main is void { Console.WriteLine("Welcome to the C# learning!!!"); //The WriteLine() method of the console class is used to display the output results} } } This is the code comment method of C# [vb]Private Sub Form_Load() Me.AutoRedraw = True FontSize = 18 : Rem Set the font size FontBold = True: Rem Make the font boldPrint "Welcome to the C# learning!!!": Rem Screen display content End Sub [vb]Private Sub Form_Load() Me.AutoRedraw = True FontSize = 18 'Set the font size FontBold = True 'Make the font boldPrint "Welcome to the C# learning!!!" 'Screen display content End Sub This is the VB code comment method. The most commonly used comment method in C# is to add double slashes after the code, that is, //. The above picture has shown it well. Of course, there is not only one comment method in C#. Double slashes are used for single-line comments. , use /*….*/ for double-line comments. Among them // is a code comment; /* this is a code comment */. Not only that, the table below introduces more annotation methods. If you are interested, you can study them. VB shows two different methods of code annotation. Anyone who has studied VB knows that there are two ways to comment in VB (I only know these two methods for the time being). One is single quotation marks, which is to add English single quotation marks after the code; the other is Rem comments, that is, after the code Add a colon, Rem, and comments after the code. Relatively speaking, the first annotation method is more common and commonly used.