5

I am trying to use the command line arguments in a GUI (.NET + WPF) C# application. I've read that in VB.NET exists something like My.Application.CommandLineArgs but I haven´t found the C# equivalent.

I have hacked the Main function in the application class to include the string[] argv parameter and pass it to the application class constructor but i don't think that will be the correct way to access the command line parameters.

What is the correct way to access it in a C# GUI WPF application?

2 Answers 2

5

Declaring argv in Main is fine, and is quite commonly used. Environment.GetCommandLineArgs allows access to them at any time (declaring argv etc. is optional). Environment.CommandLine is a lower level function which gets the raw commandline prior to its being parsed (and the exe name getting transformed etc.).

Sign up to request clarification or add additional context in comments.

2 Comments

Environment.GetCommandLineArgs can be used without declaring argv in a gui app btw, for future visitors.
@MDMoore313 Thanks, gobbled in!
3

You need to call Environment.GetCommandLineArgs(), this will give you the command line parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.