I\'m looking for a way to have a function such as:
myFunction({\"Key\", value}, {\"Key2\", value});
I\'m sure there\'s something with anonymous
Using a dictionary:
myFunction(new Dictionary(){
{"Key", value},
{"Key2", value}});
Which is straight forward, you need only one new Dictionary
, not for each argument. It's trivial to get the keys and values.
Or with an anonymous type:
myFunction(new {
Key = value,
Key2 = value});
Which is not very nice to use inside the function, you'll need reflection. This would look something like this:
foreach (PropertyInfo property in arg.GetType().GetProperties())
{
key = property.Name;
value = property.GetValue(arg, null);
}
(Staight from my head, probably some errors...)