Sunwen Tutorial----C # Advanced (i)

Source: Internet
Author: User
Before writing these articles, I knew nothing about C #. Just heard from the predecessor, said he is very like Java. Because I have been watching Java this time, the results of what Ming Tang didn't see it (only blame me too stupid:), in fact, I think there is no practice opportunities), so I would like to change the taste. , want to see this stuff, just on the m$ site a look,. NET east to more than 100 trillion! Look at the fear, not to mention all download down, to cost me a whole phone card? Fortunately, a friend of mine first. NET downloaded, I took the hard drive and ran over the cuff. A SETUP.EXE, a full 106M of the giant. So, I would like to thank this friend, Ken, without his help, there is no following article.

Writing this article, I was a little afraid, afraid of their level is not enough, wrong too much, to be scolded by others. In the process of writing, the discovery is still relatively smooth, because these and the original Java has a lot of image of the place. But Java, many predecessors have very deep research. However, because of my limited level, the error is unavoidable , if you find that there is something wrong, but also to correct, in the next grateful! My mail:mrfat@china.com. Thank you first!

The following articles apply to people who have some java/c++ programming experience, which is better if they have Java programming experience, because I compare C # with Java in many places. If you don't have any programming experience, you can go to the community of Oicq's homepage to find another series of C # tutorials, That might be better for you.

There is because the following article is in the idle time to write, more nonsense, we see not vomiting blood yo @#$%^&*! good, let's start!
Hello everybody, I am the Sunwen of Wuhan Chinese teacher, I come back again. 51 Everyone is gone, Sunwen also in the bedroom fighting, whining. Today, I would like to tell you that we have heard of a long time, but also full of God-dense language: C #.

I just got this from my friend today. m$. NET development package, from the m$ website up and down, there are 106M, so Sunwen naturally have no money to go down to him. Say Six O ' Day this morning. (Under the table: Get to the point, idiot!) again a pair of shoes flew up, this is the third pair!) Yes, I'll start right now!

When I first got the C # Reference, I saw that it was Java! Indeed, like the outside world, C # and Java are very much alike, so that a Java-savvy person can quickly grasp the structure of C #. To its internal realization mechanism, that I also not very clear, can only with everybody in the study progress together , but also hope that everyone to join in!

Well, in order to give you a clearer feeling, I first give you an example, nature is HelloWorld (old-fashioned!).

From://Helloworld\hello1.cs
001:public class Hello1
002: {
003:public static void Main ()
004: {
005:system.console.writeline ("Hello, world!");
006:}
007:}
It outputs the following results:

Hello, world!.

Some friends have already discovered, is java! only System.out.PRinln () changed to System.Console.WriteLine () just!

Let us analyze this program, the entire program consists of a public class (class), there must be a public static void Main () This method, 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. It's simple!

Here's another one:

From://Helloworld\hello2.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 uses a using, in fact, it is equivalent to the import in Java, refers to the meaning of a package. When this package is quoted, the console class in this package does not indicate the full name, as long as Console.WriteLine () is available, It is not necessary to use System.Console.WriteLine () so long that the system has been omitted.

Example three, the following shows how to display the command line parameters

From://Helloworld\hello3.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 ("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:}
As you can see, the string array, args, refers to the input parameters. Because it is a string class, there is a length method, so you can have args.length to access it. Then use a For loop to show them. As for the loop, most of these things follow the C syntax. .

Example four, if you want a return value, then you can write as follows, with return:

From://Helloworld\hello4.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! For people who understand C or Java, better understand, if it is VB or VBS users, there are some difficulties. Oh, hang on!

Well, after reading the simple example, let's go to the next lesson!

The above is the Sunwen tutorial----C # Advanced (a) of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.