Friday, July 31, 2009

Creating a C# - Console application to read in a parameter switch?

Does any know if this is possible, Creating a Console app to read in a parameter switch in C#?





For example, I created a console app in C#, then complied it. I now have an: myapp.exe





What I'm trying to do is to get:





myapp.exe -234





or





myapp.exe 234 or myapp.exe 234 345





These number(s) (234, 345) will be passed through the program as a variable....





Does anyone know if this is possible and what I need to set this up in C#.

Creating a C# - Console application to read in a parameter switch?
And adding on to what pfo said, just loop through the args:





foreach(string arg in args)


//process args
Reply:It's quite simple, in .Net the entry point can have any of the following signatures:





static void Main();


static void Main(String[] args);


static int Main();


static int Main(String[] args);





Obviously, you want an entry point that passes arguments.


No comments:

Post a Comment