SUNWEN tutorial ---- C # advanced (1)

Source: Internet
Author: User

Before writing these articles, I knew nothing about C. I heard something from my predecessors, saying that he is very similar to JAVA. because I have been reading JAVA for a long time, but I have not seen the result (I can only blame myself for being too stupid). In fact, I still have no chance to practice it), so I really want to change my taste. in fact, I have heard of C # for a long time. I just want to see this stuff on the M $ website ,. it takes more than one hundred MB for the NET stuff! I am afraid of reading it, not to mention downloading it all. I need to pay for the whole phone card? Fortunately, a friend of mine put it first. NET downloaded, and I took the hard disk and copied it. one SETUP. EXE, full of huge memory M. therefore, I would like to thank this friend, KEN. Without his help, there will be no following article.

When I wrote this article, I was a little scared. I was afraid that I was not good enough and had too many mistakes. during the writing process, it was found that it was still relatively smooth, because there were many similarities with the original JAVA. many predecessors have made deep research on JAVA. however, due to my limited level, errors are inevitable. If you find any errors, I hope you can correct them. I am very grateful! My MAIL: mrfat@china.com. Thank you first!

The following article applies to people with 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 do not have any programming experience, you can go to the community on the homepage of OICQ to find another series of C # tutorials, which may be more suitable for you.

Another reason is that the following articles are written at idle time, and there are a lot of nonsense. You should not vomit blood. @ # $ % ^ &*! Okay. Let's get started!
Hello everyone, I am SUNWEN from Wuhan Hashi and I am back. On May Day, everyone left, And SUNWEN had to fight in the dormitory. Today, I want to talk to you about the fascinating Language C # That has been heard for a long time #.

I just got M $ from my friend today. NET Development Kit, from the M $ website, There are 106 M, so SUNWEN naturally has no money to go to him. saying that at this morning ..... (stage: Enter the topic, dumb! Another pair of shoes flew up. This is the third pair !) Yes, I will start now!

When I first got a reference for C #, I saw that this was actually JAVA! Indeed, as the outside world said, on the surface, C # and JAVA are very similar, so that a person who understands JAVA can quickly master the structure of C. as a result, I am not quite clear about the internal implementation mechanism. I can only make progress together with you in your studies. I hope you can join me more!

Well, in order to give you a clearer feeling, I will first give you an example. Naturally, it is HelloWorld !).

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 changed System. out. prinln () to System. Console. WriteLine!

Next let's analyze this program. The whole program is composed of a public class, which must have a public static void Main () method, and the Execution Code is inside. system. console. writeLine ("Hello, World! ") This statement is used to print a line of Hello, World! To the Console !. Easy!

Here is another example:

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 uses a using. In fact, it is equivalent to the import in JAVA, which means to reference a package. after this package is referenced, do not specify the full name of the Console class in this package, as long as the Console. you can use WriteLine () without using System. console. writeLine () is so long that System is omitted.

Example 3: How to display command line parameters

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 :}
As you can see, the string array args refers to the input parameters. because it is a String class, there are Length methods, so there can be args. length. then a for loop is used to display them. as for loop, most of these things follow the C syntax.

Example 4: If you want to return a value, you can write it as follows and 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 :}
Easy! Haha! For those who understand C or JAVA, it is easy to understand. If it is a user of VB or VBS, it will be difficult to stay!

Now, after reading the simple example, let's take the next lesson!

 

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.