从listview控件获得了一个lvwPackageList.SelectedItems[0].Text
有一个list<>泛型集合存储了 一些的对象 如何用这个字符串来匹配我想要获得的实例对象额

解决方案 »

  1.   

     
                    List<string> listInfo = new List<string>();
                    listInfo.Add("1");
                    listInfo.Add("1");
                    listInfo.Add("1");
                    listInfo.Add("1");
                    listInfo.Add("1");
                    listInfo.Add("2");
                    listInfo.Add("21");
                    List<string> listt = listInfo.FindAll(x => x.Equals("1")).ToList();差不多就是这个意思吧
      

  2.   

    恩,看下LINQ
    就是针对List可以做类似sql query的功能
    具体看这里
    http://www.cnblogs.com/lyj/archive/2008/03/25/1119671.html
      

  3.   

     
    呵呵 看来有点没表达清楚额~~ 
    不过listInfo.Add("1");里添加的是对象。
      

  4.   

    我现在又点不解的是 如何用 获得的字符串在list集合里查找 我需要的对象
    例如student stu = new student("学生1","年龄15","女");
    List<student>studentSet = new List<student>();
    studentSet.Add(stu);根据学生1这个字段 来查找stu这个对象额
      

  5.   

    这个你还是不理解
    用Lambda表达式就是: List<student> listt = studentSet.FindAll(x => x.对应字段.Equals("学生1")).ToList();
    这个不好理解的话就循环啊
    foreach (student info in studentSet)
    {
      if (info.对应的字段 == "学生1")
      {
         这个info 就是你想要的了
      }
    }
      

  6.   

    表示 不会 Lambda表达式 额 所以才会在问一边 嘿嘿
      

  7.   

    用循环就行了,不一定非用Lambda