C#访问命令行的两种方法
作者:pythoner
这篇文章主要介绍了C#访问命令行的两种方法,实例分析了C#操作命令行的两种常用技巧,需要的朋友可以参考下
本文实例讲述了C#访问命令行的两种方法。分享给大家供大家参考。具体如下:
方法1:
// 参数:A B C
using System;
public class CommandLine
{
public static void Main(string[] args)
{
// Length 属性用于获取数组的长度。
// 注意,Length 是只读属性:
Console.WriteLine("Number of command line parameters = {0}", args.Length);
for(int i = 0; i < args.Length; i++)
{
Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
}
}
}
方法2:
// 参数:John Paul Mary
using System;
public class CommandLine2
{
public static void Main(string[] args)
{
Console.WriteLine("Number of command line parameters = {0}", args.Length);
foreach(string s in args)
{
Console.WriteLine(s);
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
