Howto someFunction(List <acceptDifferentTypesHere> list){/*反射的东西*/}

Har*_*rry 0 c# asp.net collections function

我想从列表中生成一个DataTables.

所以我有两个清单

List<typeA> listA = new List<typeA>(); 
List<typeB> listB = new List<typeB>();
Run Code Online (Sandbox Code Playgroud)

如何才能获得一个函数接受具有不同元素类型的两个(或更多)列表?

private void someFunction(List<acceptDifferentTypesHere> list)
{ 
   /*elementwise reflection stuff*/
} 
Run Code Online (Sandbox Code Playgroud)

你能帮忙的话,我会很高兴,

掠夺

msa*_*het 6

private void someFunction<T>(List<T> list)
{ 
   /*elementwise reflection stuff*/
}
Run Code Online (Sandbox Code Playgroud)

使用如下

someFunction<typeA>(listA);
someFunction<typeB>(listB);
Run Code Online (Sandbox Code Playgroud)