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

Source: Internet
Author: User
OK, I COME back, the following code shows how we can print multiple parameters:

From://Commandline\cmdline1.cs
001:using System;
002:
003:public class CommandLine
004: {
005:public static void Main (string[] args)
006: {
007:console.writeline ("Number of command line parameters = {0}", args. Length);
008:for (int i = 0; i < args. Length; i++)
009: {
010:console.writeline ("arg[{0}] = [{1}]", I, args[i]);
011:}
012:}
013:}
If your input is:

CmdLine1 A B C

Then its output is:
Number of command Line parameters = 3
Arg[0] = [A]
ARG[1] = [B]
ARG[2] = [C]

Haha, see the Secret of it! Yes {0} is a token, it tells the system, here left to the No. 0 parameter, in the program, this No. 0 parameter is I. Therefore, the print is arg[0], the surface is not arg[{0}], haha!

Example two shows you the use of the foreach statement, in fact, in ASP, this is often used:


From://Commandline\cmdline2.cs
001:using System;
002:
003:public class CommandLine2
004: {
005:public static void Main (string[] args)
006: {
007:console.writeline ("Number of command line parameters = {0}", args. Length);
008:foreach (string s in args)
009: {
010:console.writeline (s);
011:}
012:}
013:}
It is clear that args is an array, and it is a character type. The meaning of foreach is to cycle through all the elements. Run:

>cmdline2 John Paul Mary
Number of command Line parameters = 3
John
Paul
Mary
All right, comrades, take a break, I'm going to bed! 88, see you next time!

The above is the Sunwen tutorial----C # Advanced (ii) 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.