Home > Article > Backend Development > SUNWEN tutorial - C# advanced (1)
Before writing these articles, I knew nothing about C#. I only heard some from my seniors, saying that it is very similar to Java. Because I have been looking at JAVA during this period, but I didn’t see the difference (I can only blame me Too stupid:), in fact, I think there is still no chance to practice), so I really want to change my taste. In fact, I heard about C# very early and wanted to take a look at this stuff. I just went to the M$ website to take a look. NET stuff costs more than 100 megabytes! I was scared when I saw it, not to mention that downloading it all would cost me a whole phone card? Fortunately, a friend of mine downloaded .NET first, and I took the hard drive and ran over to copy it. Here it comes. A SETUP.EXE is 106M in size. Therefore, I would like to express my special thanks to this friend KEN. Without his help, there would be no following article.
When I was writing this article, I I'm a little afraid that I'm not good enough, make too many mistakes, and get scolded by others. During the writing process, I found that it went relatively smoothly, because there are many similarities with the original JAVA. As for JAVA, many seniors have very good skills. In-depth research. However, due to my limited level, mistakes are inevitable. If you find any mistakes, I would like to correct them. I would be very grateful! My MAIL: mrfat@china.com. My brother is here first. Thanks!
The following article is suitable for people who have some JAVA/C++ programming experience. If you have JAVA programming experience, it would be better, because I compare C# with JAVA in many places. If you don’t have any If you have programming experience, you can go to the community on the OICQ homepage to find another series of C# tutorials, which may be more suitable for you.
Also, because the following article was written in my free time, there is a lot of nonsense, and everyone has read it Don't vomit blood @#$%^&*! Okay, let's get started!
Hello everyone, I am SUNWEN from Wuhan China Normal University, and I am back again. Everyone has left on May Day, but SUNWEN still has to fight hard in the dormitory, ugh. Today, what I want to tell you is a language that everyone has heard for a long time and is full of mystery: C#.
I just got M$’s .NET development package from a friend today. I downloaded it from M$’s website and it’s 106M, so SUNWEN naturally doesn’t have the money to download it. By the way, at six o’clock this morning... (Audience: Let’s get to the point, idiot! Another pair of leather shoes flew up, this is the third pair!) Yes, I’ll start right away!
When I first got the C# reference, I saw it, this is simply JAVA Well! Indeed, as the outside world says, on the surface, C# and JAVA are very similar, so that a person who knows JAVA can quickly grasp the structure of C#. As for its internal implementation mechanism, I don’t know much about it. , I can only make progress together with everyone in learning, and I hope everyone will support me!
Okay, in order to give you a clearer feeling, I will first give you an example, which is of course HelloWorld (old-fashioned!).
000: // HelloWorldHello1.cs
001: public class Hello1
002: {
003: public static void Main()
004: {
005: System.Console.WriteLine("Hello, World!");
006: }
007: }
The output result is:
Hello, World!
Some friends have discovered that it is JAVA! Just change System.out.PRinln() to System.Console.WriteLine() That’s it!
Let’s analyze this program. The entire program consists of a public class, which must have a public static void Main() method, and the execution code is inside. System.Console.WriteLine("Hello , World!") The function of this statement is to print a line of Hello, World! to the console (Console). It's very simple!
Here's another one:
000: // HelloWorldHello2.cs
001: using System;
002 :
003: public class Hello2
004: {
005: public static void Main()
006: {
007: Console.WriteLine("Hello, World!");
008: }
009: }
This program Using a using is actually equivalent to import in JAVA, which means referencing a package. After referencing this package, there is no need to indicate the full name of the Console class in this package, just Console.WriteLine(). , there is no need to use System.Console.WriteLine() for such a long time, System is omitted.
Example 3, the following shows how to display the parameters of the command line
000: // HelloWorldHello3.cs
001: using System;
002 :
003: public class Hello3
004: {
005: public static void Main(string[] args)
006: {
007: Console.WriteLine("Hello, World!");
008: Console.WriteLine( "You entered the following {0} command line arguments:", args.Length );
009: for (int i=0; i < args.Length; i++)
010: {
011: Console.WriteLine(" {0}", args[i]);
012: }
013: }
014: }
You can see that the string array args refers to the input parameters. Because it is a String class, it has a Length method , so you can use args.length to access its length. Then use a for loop to display them. As for loops, most of them follow the syntax of C.
Example 4, if you want a return value, you can like Write like this, use return:
000: // HelloWorldHello4.cs
001: using System;
002:
003: public class Hello4
004: {
005: public static int Main(string[] args)
006 : {
007: Console.WriteLine("Hello, World!");
008: return 0;
009: }
010: }
It's very simple! Haha! It looks better for people who know C or JAVA I understand, if you are a VB or VBS user, you will have some difficulties. Stay tuned!
Okay, after reading the simple example, let’s move on to the next lesson!
The above is the content of the SUNWEN tutorial - C# Advanced (1). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!