之前接触一个往Console里输入参数的项目,资深QA教我怎么run,灰常脸红。
今日无事,baidu之。
Step1 写简单Console Code.
1 class Program 2 { 3 static void Main(string[] args) 4 { 5 int i = 0; 6 if (args.Length < 1) 7 Console.WriteLine("No args"); 8 else 9 foreach (string s in args) 10 { 11 { if(i<args.Length) 12 Console.WriteLine("Your command is " +args[i].ToString()); 13 i++;} 14 } 15 Console.ReadLine(); 16 } 17 }
Step 2 写入参数
右键单击Console项目,选择属性。

在文本框中输入命令,多个命令空格隔开。
Step3 运行 大功告成!

本文介绍如何在C#控制台应用程序中接收并处理命令行参数,通过实例演示了参数的读取与解析过程,适用于初学者及需要刷新知识的资深QA。
1610

被折叠的 条评论
为什么被折叠?



