c# - Method for convert generic list to another generic list -


i have data in list<one> , want convert list<two>. code

 public static list<t> listcopy<t>(list<t> input)     {         list<t> mylist = new list<t>();         //logic goes here          return mylist;     } 

this process data list<one> list<one> want process list<one> list<two>

    list<one> l = new list<one>();     list<two> t = new list<two>();     t = listconvert<two>(l); 

what can this?

you can using linq, still need provide function should used convert elements:

public static list<tresult> listcopy<tsource, tresult>(list<tsource> input, func<tsource, tresult> convertfunction) {     return input.select(x => convertfunction(x)).tolist(); } 

and sample usage (with simple casting conversion function)

var t = listconvert(l, x => (two)x); 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -