Answer the question
In order to leave comments, you need to log in
How to get C# command line argument?
Please help with command line arguments for client.bin
private void BuildClient(object o)
{
try
{
BuildOptions options = (BuildOptions) o;
var builder = new ClientBuilder(options, "client.bin");
builder.Build();
try
{
this.Invoke((MethodInvoker) delegate
{
MessageBox.Show(this,
$"Successfully built!\nSaved to: {options.OutputPath}\n\n",
"Build Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
});
}
catch (Exception)
{
}
}
catch (Exception ex)
{
try
{
this.Invoke((MethodInvoker)delegate
{
MessageBox.Show(this,
$"An error occurred!\n\nError Message: {ex.Message}\nStack Trace:\n{ex.StackTrace}", "Build failed",
MessageBoxButtons.OK, MessageBoxIcon.Error);
});
}
catch (Exception)
{
}
}
SetBuildState(true);
}
Answer the question
In order to leave comments, you need to log in
There are two ways to get command line arguments.
The first is to change the entry point function (usually Main() in Program.cs): .
Then the arguments will be in the args array.
The second way is to use Environment.CommandLine . It is convenient because you can look there at any moment of the program's operation, and not just in the function at the entry point.
static void Main(string[] args) {}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question