I am writing a .NET class that needs to parse the command line of the process. I don't want to have a dependency between the Main() method and that class. How can the class access the command line?
Call Environment.GetCommandLineArgs()
.
If you use .NET Compact Framework, Environment.GetCommandLineArgs() method isn't implemented and System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments returns always empty string, so you must use main function and pass arguments to your others classes.
An example :
[MTAThread] static void Main(String[] commandLineArguments) { CommandLineHelper.parse(commandLineArguments); } public static class CommandLineHelper { public static void parse(String[] commandLineArguments) { // add your code here } }
System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With