0

I have a winform application which I developed in c# using Visual studio. This form has only one field in UI and want to convert that to a console application which can accept one argument.

Is that possible to do that in c#? One solution I could think of is taking the value for that one UI field through command line arguments of console application.

Any other suggestions would be welcomed.

user3481630
  • 101
  • 10

2 Answers2

3

Go to Project Properties and Save output type as Console Application. Now, your Main can access parameters just like any other function. Change that function to something like this

static void Main(string[] args)
{
 if (args.Length > 0)
 {
    String paramValue1 = args[0];
 }
}

To pass the values to your main function, you need to type that in from command line

Pankaj
  • 2,618
  • 3
  • 25
  • 47
1

Yes you can change the WinApps to Console type of application, by changing the project type setting and accepting the arguments in Main(). But why would like to do that? Was there any simple WinApp which has single button used to run some batch job?

And also it depends on how the project is loosely coupled with UI. AFAIK, WinApps are rich in UI which is not easy to handle all the functionality using the console app.

good luck...

Ashwath
  • 407
  • 3
  • 10