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:
using D = System.Collections.Generic.Dictionary<string, object>;
And then you could do:
MyMethod(new D {{string1, value1},{string2, value2}});
Which is a bit shorter, but probably still not ideal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With