command line - c# - Reading commandline args with their associated values -


was wondering whether there way read in commandlines in console app values. can read in commandlines enough can't seem find info obtaining values commandline.

for example(args):

atest = 5; btest = 13; 

would there way read in arg atest associate int 5...?

thanks :)

i have written helper method me along time ago, extracts value of swtich or returns if present or not - maybe.

/// <summary> /// if arguments in format /member=value /// function returns value given membername (!casesensitive) (pass membername without '/') /// if member switch without value , switch preset given argname returned, if switch presetargname means true.. /// </summary> /// <param name="args">console-arg-array</param> /// <param name="argname">case insensitive argname without /</param> /// <returns></returns> private static string getargvalue(string[] args, string argname) {     var singlefound = args.where(w => w.tolower() == "/" + argname.tolower()).firstordefault();     if (singlefound != null)         return argname;       var arg = args.where(w => w.tolower().startswith("/" + argname.tolower() + "=")).firstordefault();     if (arg == null)         return null;     else         return arg.split('=')[1]; } 

example:

static void main(string[] args)  {     var modeswitchvalue = getargvalue(args, "mode");     if (modeswitchvalue == null)     {         //argument not present         return;     }     else     {          //do     }   } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -