好了,I COME BACK,下面的程式碼顯示了我們如何列印多個參數:
000: // CommandLinecmdline1.cs
001: using System;
002:
003: public class CommandLine005 : public static void Main(string[] args)
006: {
007: Console.WriteLine("Number of command line parameters = {0}", args.Length);
008: for(int i = 0 i(int i = i = 0; 009: {
010: Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
011: }
012: }
013: }
如果你的輸入是:
cmdline1 A B C
那麼它的輸出為:
Number of command line parameters = 3Arg[0] = [A]
Arg[1] = [ArgB]
Arg[0] = [A]
Arg[1] = [ArgB]
Arg [2] = [C]
哈哈,看出了其中的秘密了吧!是的{0}是一個標記,它告訴系統,這裡留下了給第0個參數用,在程序中,這第0個參數就是i.因此,印出來的就是Arg[0],面不是Arg[{0}]了,哈哈!
例二向大家展示了foreach這個語句的用法,其實在asp中,這個經常用到:
000: // CommandLinecmdline2.cs
001: using System;
002:
003: public class CommandLine2
004: {
005: public class CommandLine2
004: {
005: public class 007: Console.WriteLine("Number of command line parameters = {0}", args.Length);
008: foreach(string s in args)
009: {
010: Console.WriteLine(s); }
012: }
013: }
很顯然,args是一個數組,而且是字符型的.foreach的意思就是把其中的所有元素都循環完.運行得出:
Number of command line parameters = 3
John
Paul
Mary
好了,同志們,休息一下,我要睡覺了!88,下次再見!