Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to Main() C# in visual studio for mac

Tags:

c#

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!");
            }
        }
    }
}
like image 897
Zack Lucky Avatar asked Jan 21 '17 03:01

Zack Lucky


People also ask

How can we pass arguments through main () method?

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.

How many arguments can be passed to the main () in C?

The main() function has two arguments that traditionally are called argc and argv and return a signed integer.

What type of parameters are passed to main ()?

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.


1 Answers

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.

enter image description here

like image 128
Joseph Woodward Avatar answered Oct 21 '22 10:10

Joseph Woodward