C# - Arguments for application

后端 未结 5 419
野趣味
野趣味 2021-01-27 08:02

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?

Example

5条回答
  •  天涯浪人
    2021-01-27 08:54

    here is a snippet

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

    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

提交回复
热议问题