I'm currently writing a C# console application and would like to give the user the ability to chose what feature to be executed. For example, when I start MyApp.exe -help
the help should show, or when I start MyApp.exe -shutdown
the computer should shutdown. How do I pass/check that?
My current code doesn't seem to work:
static void Main(string[] args)
{
if (args.Equals("-help"))
{
Console.WriteLine("Some help here...");
}
}
args
is an array. And then read learn.microsoft.com/en-us/dotnet/csharp/programming-guide/… or dotnetperls.com/mainargs.Equals("-help")
checks if the array object is equal to-help
, not if one of its items equals-help
. How might you achieve the latter (which is what you want)?