C# - 参数应用 [英] C# - Arguments for application

查看:100
本文介绍了C# - 参数应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能使它所以当有添加到程序名称末尾参数它特定的方法或什么?

How can I make it so when there are arguments added to the end of the program name it does a specific method or whatever?

此外,有没有一个名字呢?

Also, is there a name for this?

例如:

PROGRAM.EXE / I

program.exe /i

我也见过%1

推荐答案

下面是一个片段

class myclass
{
  public static void main(string [] args)
  {
    if(args.Length == 1)
    {
       if(args[0] == "/i")
       {
         Console.WriteLine("Parameter i");
       }
    }
  }
}

%1实际上是语法BAT文件通过传递参数。所以,如果你看到PROGRAM.EXE%1在一个名为cmd.bat,您可以拨打cmd.bat / i和/我将通过传递到PROGRAM.EXE

The %1 is actually syntax for BAT files to pass the parameter through. So if you see program.exe %1 in a file named cmd.bat, you can call cmd.bat /i and the /i will be passed through to program.exe

这篇关于C# - 参数应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆