I want to deploy a piece of software to pcs that will need to be able to tell the program a few pieces of information. I do not want to use a configuration file because the exe will be located on a shared drive and they will not have access to run their own config. Would a command line parameter be the best way to do this? If so, how would I pass this and pick it up inside of a c# program?
If you dont want to override the main method, you can use the Environment class.
foreach (string arg in Environment.GetCommandLineArgs())
{
Console.WriteLine(arg);
}
Yes the command line is a good way of passing information to a program. It is accessible from the Main
function of any .Net program
public static void Main(string[] args) {
// Args is the command line
}
From elsewhere in the program you can access it with the call Environment.GetCommandLineArgs
. Be warned though that the command line information can be modified once the program starts. It's simply a block of native memory that can be written to by the program
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