[英]How to compare list of strings and list of objects which have one of the data member same as first list
I have User
class and in that data members are 我有
User
类,其中的数据成员是
public string userid {get;set;}
public string FirstName {get;set;}
public string LastName {get;set;}
public string address {get;set;}
public string mobilenumber {get;set;}
I have another list of string which contain only userid
in form of string. 我还有另一个字符串列表,其中仅包含字符串形式的
userid
。
I want to compare userid
of first list with the string in the second list 我想将第一个列表的
userid
与第二个列表中的字符串进行比较
What is the LINQ query for that? LINQ查询是什么?
If the userid
did not match with the string then query should return object present in that list. 如果
userid
与字符串不匹配,则查询应返回该列表中存在的对象。
I'll assume you have a List<User>
called Users and a List<string>
called listOfUserIds. 我假设您有一个名为Users的
List<User>
和一个名为listOfUserIds的List<string>
。 Then you can use the following Linq query to get all the Users who's Ids do not exist in listOfUserIds. 然后,您可以使用以下Linq查询来获取listOfUserIds中不存在的所有ID用户。
Users.Where(user => !listOfUserIds.Any(id => id == user.userid));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.