I’m trying to send a Dictionary as a parameter to a method. It works, but it’s getting a bit tedious. I’m doing it a million times and I’d like to do it a little slicker if at all possible. Right now, this is how it looks:
MyMethod(new Dictionary<string, object> { { string1, value1 }, { string2, value2 } });
I’d like to get it to look more like this:
MyMethod({ string1, value1 }, { string2, value2 });
Is this a pipe dream? Any ideas on how to do that?
I don’t think there’s any way to get the type of syntax you’re looking for. The closest, and shortest thing I can think of would be to define something like:
And then you could do:
Which is a bit shorter, but probably still not ideal.