.net 实用小技巧

Linq 实现in查询

Dictionary<int, IP> dict = new Dictionary<int, IP>();
dict.Add(1, new IP("192.168.100.1", 81, 11));
dict.Add(2, new IP("192.168.100.2", 82, 12));
dict.Add(3, new IP("192.168.100.3", 83, 13));
dict.Add(4, new IP("192.168.100.4", 84, 14));
dict.Add(5, new IP("192.168.100.5", 85, 15));
dict.Add(6, new IP("192.168.100.6", 86, 16));
dict.Add(7, new IP("192.168.100.7", 87, 17));

int[] ac = new int[]{2,3};
var res = from p in dict
where ac.Contains(p.Key)
where p.Value.Address == "192.168.100.5"
select p;

posted @ 2015-07-09 15:34  常平  阅读(251)  评论(0编辑  收藏  举报