public List Test(List listData, string comboText) {} 我想实现一个方法,用户传递一个List对象和T对象中的一个字段名称给我,我通过这两个条件获取List集合中comboText这个字段的值。我想应该是通过反射实现这个方法,但是才疏学浅,还请大家帮帮忙。。
通过泛型查找不同属性的值
public class Finder
{
// 定义一个泛型方法,用来查找指定值在数组中的索引
public static int Find<T>(T[] items, T item)
{
for (int i = 0; i < items.Length; i++)//遍历泛型数组
{
if (items[i].Equals(item))//判断是否找到了指定值
{
return i;//返回指定值在数组中的索引
}
}
return -1;//如果没有找到,返回-1
}
}