C#进阶2

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值