views:

402

answers:

2

A beginner question. 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.

Which is the correct way to access a C# GUI WPF application?

Thaks in advance

+2  A: 

declaring argv in Main is fine, and is quite commonly used. Environment.GetCommandLineArgs gets them afterwards. Environment.CommandLine is a low level function which gets the raw commandline prior to its being parsed (and the exe name getting transformed etc.).

Ruben Bartelink
voted the first one... thanks
jab
+2  A: 

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

Matt Warren
+1 (Fixed mine based on this, ta)
Ruben Bartelink