I have a method that I want to pass in a couple of arr开发者_StackOverflow中文版ays that are linked, ie item 1 in array 1 corresponds to item 1 in array 2.
I can obviously just pass in 2 arrays, like this:
meth({"v1", "x1"}, {"v2", "x2"});
But was wondering if C#3.0 (not able to use 4.0 here yet) had any "syntactic sugar" options to handle this, eg via anonymous types, dictionaries or something.
For example was trying an array of anonymous types like this:
meth({ new { foo = "v1", bar = "v2" }, new { foo = "x1", bar = "x2" }});
But thats not valid (and more longwinded)...
Not sure how it could be done in one line with a dictionary, guess it would need to be split into a few lines...
var d = new Dictionary<string, string>();
d["v1"] = "v2"; d["x1"] = "x2";
Thanks in advance for any thoughts/tips, Chris.
How about using params
?
精彩评论