从类/对象列表中查找匹配的字符串

pal*_*hta 2 c# arrays string

我有一个字符串数组:

string[] PropertyIds= new string[5];
Run Code Online (Sandbox Code Playgroud)

List类(Property)

List<Property> properties = new List<Property>();
Run Code Online (Sandbox Code Playgroud)

该类Property有以下字段: PropertyId(string)和PropertyDesc(string)

我必须在数组PropertyIds中找到PropertyId的所有值,这些值不在List属性中.

例如

 string[] PropertyIds= new string[] { "one", "two", "three" };
List<Property> properties = new List<Property>()
{ 
  new Property("one","This is p1"),
  new Property("Five","This is p5"),   
  new Property("six","This is p6"),
};
Run Code Online (Sandbox Code Playgroud)

然后我的结果应该是两个三个.

Ser*_*kiy 5

使用Enumerable.Except从两个序列中获得差异:

var result = PropertyIds.Except(properties.Select(p => p.PropertyId));
Run Code Online (Sandbox Code Playgroud)