• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

C#进阶(二)

发布: 2007-6-30 23:38 | 作者: admin | 来源: | 查看: 11次 | 进入软件测试论坛讨论

领测软件测试网      SUNWEN教程之----C#进阶
  (二)
  [email protected]
  好了,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,下次再见!
  

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网