mercredi 3 février 2021

Return a generic type base on something in C#

I have a method that has to return a list of some type according to some id (I know what type the function will return according to the id):

public List<T> getList<T> (string id){

//pick url from id (I have a map with this information)
//get list from url
return List<T>;
}

I'm going to use this method inside a loop, as there are five different types

foreach (string id in listOfIds){
// var list = getList(id);
// do something with list;
}

Anyone know how to solve this issue?





Aucun commentaire:

Enregistrer un commentaire