开发者

Generic List<T> as parameter on method

开发者 https://www.devze.com 2022-12-10 02:40 出处:网络
How can I use a List<T> as a parameter on a meth开发者_StackOverflowod, I try this syntax : void Export(List<T> data, params string[] parameters){

How can I use a List<T> as a parameter on a meth开发者_StackOverflowod, I try this syntax :

void Export(List<T> data, params string[] parameters){

}

I got compilation error:

The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)


To take a generic List<T> vs a bound List<int> you need to make the method generic as well. This is done by adding a generic parameter to the method much in the way you add it to a type.

Try the following

void Export<T>(List<T> data, params string[] parameters) {
 ...
}


You need to make the method generic as well:

void Export<T>(List<T> data, params string[] parameters){

}


public static  List<T> pesquisa_lista<T>(string campo, string valor, List<T> lista)  
{
   return new List<T>();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消