gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:16:01 25 4
gpt4 key购买 nike

我有一个字符串数组:

string[] PropertyIds= new string[5];

类(属性)的列表

List<Property> properties = new List<Property>();

Property 类具有以下字段:PropertyId(字符串)和PropertyDesc(字符串)

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

例如

 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"),
};

那么我的结果应该是

最佳答案

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

var result = PropertyIds.Except(properties.Select(p => p.PropertyId));

关于c# - 从类/对象列表中查找匹配的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14437207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com