当前位置: 代码迷 >> C# >> c#泛型List<T>淘选
  详细解决方案

c#泛型List<T>淘选

热度:86   发布时间:2016-05-05 03:16:18.0
c#泛型List<T>筛选
public class People
{
     public string Name;
     public string Age;
}
class Program()
{
       static void Main(string[] args)
        {
            People people = new People();
            people.Sex = "男";
            people.Name = "Martin";
            List<People> list = new List<People>();
            list.Add(people);
            Open<People> open = new Open<People>();
            open.Display(list);
        }
}
   public class Open<T>
    {
        public void Display(List<T> list)
        {
            //通过传入进来的List<T> list进行linq或者lambda筛选
           //求大神来解决  泛型List<T>不是已知的集合

        }
    }

------解决思路----------------------
        public class Open<T>
        {
            public void Display(List<T> list, Func<T, bool> filter)
            {
                foreach (T value in list)
                {
                    if (filter(value))
                    {
                        //通过传入进来的List<T> list进行linq或者lambda筛选
                        //求大神来解决  泛型List<T>不是已知的集合
                    }
                }
            }
        }
            open.Display(list, value => value.Sex == "男");
  相关解决方案