list.Except() 差集

 

 

List<string> list = new List<string>()
            {
                "1111",
                "22222",
                "3333",
            };
            List<string> list2 = new List<string>()
            {
                "1",
                "2",
                "3",
                 "1111",
            };
            List<string> numbers2 = Enumerable.Except(list, list2).ToList();//返回22222、3333   返回的差集的数据以first为主
   List<string> fromLocal = otherPlayerDic.Keys.ToList();

   List<string> updateClientList = fromServer.Intersect(fromLocal).ToList();需要更新的列表
   List<string> newClientList = fromServer.Except(fromLocal).ToList();//新增连接列表
   List<string> deletedClientList = fromLocal.Except(fromServer).ToList();//已掉线设备列表

 

posted @ 2025-09-09 18:19  WalkingSnail  阅读(13)  评论(0)    收藏  举报