SUNWEN教程之----C#进阶(二)
2003-12-29 12:47:40 来源:WEB开发网 闂傚倸鍊搁崐鎼佸磹閹间礁纾归柟闂寸绾惧綊鏌熼梻瀵割槮缁炬儳缍婇弻鐔兼⒒鐎靛壊妲紒鎯у⒔閹虫捇鈥旈崘顏佸亾閿濆簼绨绘い鎺嬪灪閵囧嫰骞囬姣挎捇鏌熸笟鍨妞ゎ偅绮撳畷鍗炍旈埀顒勭嵁婵犲嫮纾介柛灞捐壘閳ь剛鎳撻~婵嬪Ω閳轰胶鐤呯紓浣割儐椤戞瑩宕ョ€n喗鐓曟い鎰靛亝缁舵氨绱撻崘鈺傜婵﹤顭峰畷鎺戔枎閹搭厽袦婵犵數濮崑鎾绘⒑椤掆偓缁夌敻骞嗛悙鍝勭婵烇綆鍓欐俊鑲╃磼閹邦収娈滈柡灞糕偓鎰佸悑閹肩补鈧尙鏁栧┑鐐村灦閹稿摜绮旈悽绋课﹂柛鏇ㄥ灠閸愨偓濡炪倖鍔﹀鈧繛宀婁邯濮婅櫣绱掑Ο璇茶敿闂佺ǹ娴烽弫璇差嚕婵犳碍鏅插璺猴工瀹撳棝姊虹紒妯哄缂佷焦鎸冲畷鎴﹀箻鐠囧弶宓嶅銈嗘尰缁嬫垶绂嶉悙顒佸弿婵☆垳鍘ф禍楣冩倵濮樼偓瀚�

好了,I COME BACK,下面的代码显示了我们如何打印多个参数:
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 < args.Length; i++)
009: {
010: Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
011: }
012: }
013: }
如果你的输入为:
cmdline1 A B C
那么它的输出为:
Number of command line parameters = 3
Arg[0] = [A]
Arg[1] = [B]
Arg[2] = [C]
哈哈,看出了其中的秘密了吧!是的{0}是一个标记,它告诉系统,这里留下了给第0个参数用,在程序中,这第0个参数就是i.因此,打印出来的就是Arg[0],面不是Arg[{0}]了,哈哈!
例二向大家展示了foreach这个语句的用法,其实在asp中,这个经常用到:
000: // 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: }
很显然,args是一个数组,而且是字符型的.foreach的意思就是把其中的所有元素都循环完.运行得出:
>cmdline2 John Paul Mary
Number of command line parameters = 3
John
Paul
Mary
好了,同志们,休息一下,我要睡觉了!88,下次再见!
赞助商链接