如果要通过命令行传递参数,请在C#中使用命令行参数-
当我们使用c#创建程序时,将使用static void main,并且可以在其中看到参数。
class HelloWorld {
static void Main(string[] args) {
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}string [] args是一个变量,具有从命令行传递的所有值,如上所示。
现在要打印这些参数,假设我们有一个参数“ One”-
Console.WriteLine("Length of the arguments: "+args.Length);
Console.WriteLine("Arguments:");
foreach (Object obj in args) {
Console.WriteLine(obj);
}上面将打印-
Length of the arguments: 1 Arguments: One