Sanjna Malpani
Sanjna Malpani

Reputation: 175

Pass arguments through Main(string[] args) in VS

How do i pass arguments to through Main(string[] args) when I am trying to run multiple projects through Visual Studio.

I normally right click on the project and select: Debug -> Start new instance. At this point how do I pass arguments?

Upvotes: 3

Views: 10040

Answers (3)

Keppy
Keppy

Reputation: 491

Here one Console App example

using System;
class Program
{
    static void Main(string[] args)
    {
        for (int i = 0; i < args.Length; i++) // Loop through array
        {
            Console.WriteLine(args[i]);
        }
        Console.ReadLine();
    }
}

"C:\ConsoleApp1.exe" a b c

OUTPUT:

a
b
c

Upvotes: 1

Patrick Hofman
Patrick Hofman

Reputation: 156958

If you are running with a debugger, you can change the way the application is called through the Project Settings.

Open Project Settings > Debug, and set Command Line Arguments.

enter image description here

Upvotes: 12

Fredrik
Fredrik

Reputation: 2317

Right click the project, select Properties. Under the Debug tab, you can pass in command line arguments

Upvotes: 4

Related Questions