Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在值列表中查找项,然后设置布尔属性_C#_.net_Linq_List_C# 4.0 - Fatal编程技术网

C# 如何在值列表中查找项,然后设置布尔属性

C# 如何在值列表中查找项,然后设置布尔属性,c#,.net,linq,list,c#-4.0,C#,.net,Linq,List,C# 4.0,我有一个类型为(IEnumerable)的变量中的项列表 如何检查像Person.医生或Person.工程师这样的名字 var list = PersonList(); list contains an array like list[0] = PersonDoctor, list[1] = PersonEngineer and so on. Now, if I want to check the PersonEngineer and further a property named "na

我有一个类型为(IEnumerable)的变量中的项列表

如何检查像Person.医生或Person.工程师这样的名字

var list = PersonList();

list contains an array like list[0] = PersonDoctor, list[1] = PersonEngineer and so on.

Now, if I want to check the PersonEngineer and further a property named "name" inside that and then set a boolean condition if that property presents with the value of "Steve", how to do that?

如果是这样,那么将布尔值设置为true。

您的问题中没有太多细节,因此我将假设一些事情

例如,我假设您有一个要搜索列表的字符串(让我们称这个变量为name)和一个布尔值(让我们称它为bool


如果这不是您想要的,请提供一些细节,例如代码片段,以便我们了解您的问题。

您的问题不清楚。您的列表类型是什么。PersonEngineer是一个类还是一个特定的实例,这是变量的名称吗?帮助了我。事实上,我使用的是列表中的第一种方法,它说它不能从一个人变成一个傻瓜,我简直是疯了
if (list.Any(person => person.Doctor == **name**)) 
    bool = true;