c# - avoid type repetition in class member initializer? -
Is there a way to avoid repeat typing in such a declaration of a member of the class?
Dictionary & lt; String, int & gt; MyDict = New Dictionary & lt; String, int & gt; ();
No, you only use var
for local variables Can be used . Basically you're stuck with a repetition, I'm scared.
Eric Lipert is a great one.
Interesting thing to note: Java gives the underlying typing and type of conclusions by other means, depending on what you're trying to specify to This means it's legal:
// Note: this is Java, not C #! Class Collection Help {Public Stable & lt; T & gt; & Lt; T & gt; NewList () {New Array List & lt; T & gt; (); }} // in another class (does not have to be static) static catalog & lt; String & gt; Name = CollectionHelper.NewBlast ();
Comments
Post a Comment