当前位置: 移动技术网 > IT编程>开发语言>.net > 使用Linq查找重复

使用Linq查找重复

2018年08月28日  | 移动技术网IT编程  | 我要评论

3岁宝宝吃什么奶粉,imeutil.exe,半透明校服露内衣

 1 namespace removethesame
 2 {
 3     class program
 4     {
 5         static void main(string[] args)
 6         {
 7             list<user> list = new list<user>()
 8             {
 9                 new user{id=1,name="user1",pwd="123"},
10                 new user{id=2,name="user1",pwd="123"},
11                 new user{id=3,name="user2",pwd="123"}
12             };
13             getthesame(list, out string tkey);
14             console.writeline($"the same is {tkey}");
15             console.readkey();
16         }
17         public static void getthesame(list<user> listold, out string tkey/*,out user user*/)
18         {
19             tkey = null;
20             var result = from x in listold
21                          group x by x.name into g
22                          where g.count() > 1
23                          select g;
24             foreach (var item in result)
25             {
26                 tkey = item.key;
27             }
28         }
29     }
30     public class user
31     {
32         public string name { get; set; }
33         public int id { get; set; }
34         public string pwd { get; set; }
35 
36     }
37 }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网