List多个字段标识过滤

 

class Program
{
   public static void Main(string[] args)
  {

    List<T> list = new List<T>();
    list.Add(new T() { orderid = 1, houseid = 1 });
    list.Add(new T() { orderid = 1, houseid = 1 });
    list.Add(new T() { orderid = 1, houseid = 2 });
    list.Add(new T() { orderid = 1, houseid =3 });
    list.Add(new T() { orderid = 2, houseid = 1 });
    list.Add(new T() { orderid = 2, houseid = 2 });
    list.Add(new T() { orderid = 2, houseid = 2 });
    list.Add(new T() { orderid = 2, houseid = 3 });

    var _list= list.Where((x, y) => list.FindIndex(a => a.orderid == x.orderid&&a.houseid==x.houseid) == y); 

  }
  public class T {
    public long orderid { get; set; }
    public long houseid { get; set; }
  }
}

 

_list 结果如下:

 

new T() { orderid = 1, houseid = 1 }
new T() { orderid = 1, houseid = 2 }
new T() { orderid = 1, houseid = 3 }
new T() { orderid = 2, houseid = 1 }
new T() { orderid = 2, houseid = 2 }
new T() { orderid = 2, houseid = 3 }

posted on 2017-02-21 11:25  依然照旧  阅读(525)  评论(5编辑  收藏  举报