The----of the Sunwen Tutorial C # advanced 2

Source: Internet
Author: User
Tags foreach command line
Tutorial Sunwen Tutorial----C # Advanced
Two
Mrfat@china.com
OK, I COME back, the following code shows how we print multiple parameters:

M://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 tag, it tells the system, here is left to the No. 0 parameter, in the program, this No. 0 parameter is I. So, print out is arg[0], face is not arg[{0}], haha!

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


M://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:}
Obviously, args is an array, and it's a character type. foreach means to loop through all the elements. Run it:

>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!




Next page


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.