c# - Call a generic method with a generic method -


i annoyed because call generic method generic method..

here code:

public list<y> getlist<y>(                 string atablename,                 bool awithnochoice) {   this.tablename = atablename;   this.withnochoice = awithnochoice;    datatable dt = returnresults.returndatatable("spp_getspecificparameterslist", this);    //extension de la classe datatable   list<y> resultlist = (list<y>)dt.tolist<y>();    return resultlist;   } 

so in fact when call tolist extension datatable class (learned here)

the compiler says y not non-abstract type , can't use .tolist<> generic method..

what doing wrong?

thanks reading..

change method signature to:

public list<y> getlist<y>(                 string atablename,                 bool awithnochoice) y: new() 

the reason need because custom extension-method use imposes new() constraint on generic type argument. needs to, since creates instances of type populate returned list.

obviously, have call method generic type argument represents non-abstract type has public parameterless constructor.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -