简体   繁体   English

如何比较具有与第一个列表相同的数据成员之一的字符串列表和对象列表

[英]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.

相关问题 LINQ - 比较List对象和字符串列表 - LINQ - Compare List objects and List of strings C# 程序计算有多少字符串与列表中的第一个和最后一个字符相同 - C# program to count how many strings have the same first and last chars as these in a list 如何在具有两个属性的对象列表中检查具有相同属性的所有对象是否也具有相同的其他属性? - How to check if in a list of Objects with two properties, all Objects with one equal property also have the same other property? 我有一个包含XML字符串的列表。 如何根据XML属性之一对该列表进行排序? - I have a list which contains XML strings. How can I sort this list according to one of the XML attribute? 使用与第一个列表相同的顺序对对象列表中的多个列表进行排序 - Sort multiple list inside List of objects with the same order of the first list 如何辨别列表中的哪些对象与相同类型的另一个对象最相似? - How can I tell which objects in a list have the most in common with another object of the same type? 如何将列表与同一集合中的其他列表进行比较 - How to Compare List with Other List in same Collection 如何将数据网格绑定到一个成员是列表的类? - How to bind a datagrid to a class in which one member is a list? 如何将字符串列表与列表中的元素可能有字母被打乱的字符串进行比较? - How to compare list of strings to a string where elements in the list might have letters be scrambled up? 比较Array List中的对象 - Compare objects in Array List
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM