1

I want create some console application. This application will work by parameters from input args[] array.

Like this: > app.exe -arg1 -arg2 -arg3:str3 -arg4:str4 -arg5 etc.

Where -arg1, -arg2, -arg5 the parameters for initialization variables in my app. The -arg3:str3 and -arg4:str4 the parameters with any string.

For example, if I sent the -arg1 then in my app I need initialization the var1 by any string. Like this:

foreach (string s in args)
{
    if(s.contains("-arg1")) someString1 = "someVal1";
    if(s.contains("-arg2")) someString2 = "someVal2";
    if(s.contains("-arg5")) someString5 = "someVal5";
    if(s.contains("-arg3")) someString3 = s.split(':')[1];
    if(s.contains("-arg4")) someString4 = s.split(':')[1];
}

I think that my solution is bad, because I need to test every argument in a loop and if I want to pass more new parameters I have to add new conditions.

Tell me please, maybe there are specific approaches to solving my problem? Or maybe there is some design pattern for such tasks?

EDIT: I can't use any libraries

netwer
  • 737
  • 11
  • 33

0 Answers0