|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
check console argsmy consoleApp.exe can take either 1, 2 or 3 parms what's the best way to check for these conditions? my guess is something like: if (args.Length == 2) { //there were 2 parms passed } if (args.Length == 3) { //there were 3 parms passed } is that the best way? thanks, rodchar
Show quote
Hide quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message Depends on how you're going to use them. For example, iterating them may be news:41289996-CAD0-4DD6-87F1-BA9BBC96D0AB@microsoft.com... > > my consoleApp.exe can take either 1, 2 or 3 parms what's the best way to > check for these conditions? > > my guess is something like: > > if (args.Length == 2) > { > //there were 2 parms passed > } > if (args.Length == 3) > { > //there were 3 parms passed > } > is that the best way? all you need - if you only care *what* the parameters are, and not really how *many*. Or a switch statement based on the count. Or whatever makes sense. Nothing magical here - you're just dealing with an array in any way you wish. foreach (string arg in args) { .... } Not really a wrong or right, but I'd do this:
string param1 = string.Empty; string param2 = string.Empty; string param3 = "DEFAULTVALUE"; if (args.Length >= 1) { param1 = args[0]; } if (args.Length >= 2) { param2 = args[1]; } if (args.Length >= 3) { param3 = args[2]; } Show quoteHide quote "rodchar" <rodc***@discussions.microsoft.com> wrote in message news:41289996-CAD0-4DD6-87F1-BA9BBC96D0AB@microsoft.com... > hey all, > > my consoleApp.exe can take either 1, 2 or 3 parms what's the best way to > check for these conditions? > > my guess is something like: > > if (args.Length == 2) > { > //there were 2 parms passed > } > if (args.Length == 3) > { > //there were 3 parms passed > } > is that the best way? > > thanks, > rodchar thanks all for the help,
rod. Show quoteHide quote "rodchar" wrote: > hey all, > > my consoleApp.exe can take either 1, 2 or 3 parms what's the best way to > check for these conditions? > > my guess is something like: > > if (args.Length == 2) > { > //there were 2 parms passed > } > if (args.Length == 3) > { > //there were 3 parms passed > } > is that the best way? > > thanks, > rodchar
Other interesting topics
OT: missing posts
Linq to Sql Exception Specified cast is not valid LINQ Max Linq to Sql insert fails C# Export Excel to client side Application configuration settings - Do I make global? Remoting, how to create the remote server show and hide and iframe from code behind not using button click g Logical and Visual Trees Key / Value File Facility |
|||||||||||||||||||||||