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;
namespace helloWorld
{
class MainClass
{
public static void Main(string[] args)
{
if (args.Length > 0)
{
Console.WriteLine("Hello " + args[0]);
}
else
{
Console.WriteLine("Hello World!");
}
}
}
}
If you look at the Java main method syntax, it accepts String array as an argument. When we pass command-line arguments, they are treated as strings and passed to the main function in the string array argument. The arguments have to be passed as space-separated values.
The main() function has two arguments that traditionally are called argc and argv and return a signed integer.
The main function can be defined with no parameters or with two parameters (for passing command-line arguments to a program when it begins executing). The two parameters are referred to here as argc and argv, though any names can be used because they are local to the function in which they are declared.
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.
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