Is a variant of this possible with C# Generics? -
am trying achieve impossible or unnecessary? code in getlist same specializations of class a, apart bit create new instance of specialization. there no default constructor, same list of parameters.
at moment using instead public static list<a> getlist(int i, func<a> createmeaninstance)
which feels unclean.
abstract class { protected (int i) { } public static list<t> getlist<t>(int i) t : { var list = new list<t>(); for(int x = 1; x< 100; x++) { var o = new t(i); list.add(o); } } } public class b : { public b (int i) : base(i) {} } ... var list = a.getlist<b>(1);
you can't call parameterized constructors on generic types. func<> version best approach here.
Comments
Post a Comment