c# - How to pass key value pairs from console app to a Dictionary -
i want pass arguments app so:
app.exe mode=1 thread=single and want convert these dictionary of key-value pairs. one-line suggestions?
this basic , doesn't take error conditions account:
var dictionary = args.select(a => a.split('=')) .todictionary(a => a[0], => a.length == 2 ? a[1] : null); some of potential errors are:
- duplicate names
- more 1
=
dealing makes little uglier:
var dictionary = args.select(a => a.split(new [] {'='}, 2)) .groupby(a => a[0], => a.length == 2 ? a[1] : null) .todictionary(g => g.key, g => g.firstordefault());
Comments
Post a Comment