欢迎光临
我们一直在努力

SUNWEN教程之—-C#进阶2-.NET教程,C#语言

建站超值云服务器,限时71元/月

sunwen教程之—-c#进阶
(二)
mrfat@china.com  
好了,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,下次再见!
  

  

下一页

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » SUNWEN教程之—-C#进阶2-.NET教程,C#语言
分享到: 更多 (0)