gpt4 book ai didi

c# - 检查列表中的对象是否具有特定字段内容

转载 作者:太空宇宙 更新时间:2023-11-03 19:09:54 27 4
gpt4 key购买 nike

抱歉问题标题,我真的不知道如何用一句话来解释它......

我有这样一个类

public class xyz
{
public static string attr1;
public static string attr2;
public static string attr3;
}

我如何检查 List<xyz> 中是否存在 attr1=="aaa"的对象? ?

有没有类似的东西

List<xyz> MyList = new List<xyz>();

[...]

bool attr1_exist = MyList.attr1.Contains("aaa");

?

最佳答案

应该这样做:

bool attr1_exist = MyList.Exists(s=> s.attr1 == "aaa")

关于c# - 检查列表中的对象是否具有特定字段内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599779/

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