I\'ve looked at the different resources for other editions of visual studio but it\'s not clear to me how to call Main with an arg here
using System;
namesp
Arguments can be supplied to your application within Visual Studio for Mac by right clicking on your console application in the right hand pane then going Options
> Run
> Configurations
> Default
where you'll see an Arguments
text field.
I know this is an old post, but I think that it would be good to provide an answer for those looking to use the terminal.
When installing Visual Studio:Community Edition on MacOS you are given a suite of tools. Including csc and mono.
So to run a C# console program like the one below you will need to use both tools:
using System;
namespace helloWorld
{
class Program
{
static void Main(string[] args)
{
string name = args[0];
Console.WriteLine("Hello {0}", name);
}
}
}
Then compile the C# project by running csc:
$ csc Program.cs
If there are no errors csc will then create an executable file .exe, use mono to run the executable and pass the arguments:
$ mono Program.exe Bob
Hello Bob
With these two tools you can compile, and execute the C# program.
As Joseph Woodward stated, you supply them in the arguments field under
Project Options > Run > Configurations > Your_configuration_here
.
Note that a project rebuild is necessary for these arguments to successfully be passed into Main - otherwise args
will continue to be null.
The arguments to main will be command line parameters. If running from within visual studio, you can setup the the
command line arguments
property in the "configuration properties" of your project.
For running it from command line, just invoke the exe file with parameters.
Path/to/YourProg.exe arg1 arg2
For some reason, the answer from @JosephWoodward isn't working for me. It looks like a Visual Studio bug, but I do have a workaround; the consequence is that you have to provide the arguments every time you want to start the app.