c# - Shortcuts for overly terse generic types -
i'd pass parameter of dictionary method.
public static void method(dictionary<string, string> hash) i'd use inline collection initializer
this not legal
method({{"foo", "bar"}, {"bing", "bong"}}) neither this
method(new {{"foo", "bar"}, {"bing", "bong"}}) this is
// outside class using d = system.collections.generic.dictionary<string, string>; // calling type alias method(new d {{"foo", "bar"}, {"bing", "bong"}}) so this
// once in library somewhere class sd : system.collections.generic.dictionary<string, string> {} // calling class method(new sd {{"foo", "bar"}, {"bing", "bong"}}) do have shortcut i'm not aware of solving type collection initialization?
no, can't declare dictionary way you're wanting. in c#6, there prettier dictionary initializer syntax, it's not want:
using d = system.collections.generic.dictionary<string, string>; //... method(new d { ["foo"] = "bar", ["bing"] = "bong" });
Comments
Post a Comment