C # advanced 2

zhaozj2021-02-17  60

Sunwen Tutorial ---- C # advanced

(two)

Mrfat@china.com

Ok, I com back, the following code shows how we print multiple parameters:

000: // 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

009: {

010: console.writeline ("arg [{0}] = [{1}]", i, args [i]);

011:}

012:}

013:}

If your input is:

CMDLINE1 A B C

Then it's output: Number of command line parameters = 3ARG [0] = [a] arg [1] = [b] arg [2] = [c]

Haha, I saw the secret! Yes {0} is a tag, it tells the system, here left the 0 parameter, in the program, this 0 parameter is i. Therefore, print It's been arg [0], and the face is not arg [{0}], haha!

Example I show you the usage of the foreach statement, in fact, this is often used in ASP:

000: // CommandLine / Cmdline2.cs

001: using system;

002:

003: Public class commandline22003: 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 is characteristic. What is the meaning of Foreach is to loop all of them. Run:

> cmdline2 john paul mary

Number of Command line parameters = 3

John

Paul

Mary is good, comrades, take a break, I have to sleep! 88, next time you see!

Next page

转载请注明原文地址:https://www.9cbs.com/read-29753.html

New Post(0)