how to pass args to console app?

R

Ron

Hello,

how do you pass args to a console app?

class TestApp
{
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TestApp testApp = new TestApp();
testApp.Start(args);
}

public void Start(string[] args)
{
...
)
}

Thanks,
Ron
 
P

Peter Rilling

In VS.NET, open properties dialog for the project and select the debugging
tree item. Enter the parameters in the Command Line Arguments setting.

At the command prompt, the parameters follow the name of the add name.
 
Z

Zoury

hi Ron! :O)
how do you pass args to a console app?

//***
using System;

namespace ConsoleArgsProject
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
Console.WriteLine(args[0]);

Console.WriteLine();
Console.WriteLine("Press Enter to quit...");
Console.ReadLine();
}
}
}
//***

now if you actually want to test it (i don't have the exact menu/item names)
:

- open the Project Properties (from the Project menu, last item in the list)
- go in the configuration properties
- select debugging
- you can add a test arguments line in there
- start your app
 
J

Jon Skeet [C# MVP]

Ron said:
how do you pass args to a console app?

class TestApp
{
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
TestApp testApp = new TestApp();
testApp.Start(args);
}

public void Start(string[] args)
{
...
)
}

Not really sure what you mean here - are you talking about creating a
new process with Process.Start? If so, you can use
ProcessStartInfo.Arguments, although you'll need to concatenate all the
arguments together and quote any that have spaces in.
 
R

Ron

Thanks all for your replies. The solution was to enter
the args in the Debug Command Line in the Project
Properties. That worked! Thanks all for letting me know
about this.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top