Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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中使用linq检查列表中是否存在两个值#_C#_Linq - Fatal编程技术网

C# 如何在c中使用linq检查列表中是否存在两个值#

C# 如何在c中使用linq检查列表中是否存在两个值#,c#,linq,C#,Linq,我有一个linq语句,看起来像这样: if(items.Any(x => x.CustomerID == 4)) { } 但是,我希望在项目列表中找到一个对象,该对象不仅包含customerID为4,还包含designID为6 我知道我能做到: if(items.Any(x => x.CustomerID == 4) && items.Any(x => x.DesignID == 6)) { } 但这可能不起作用,因为我需要找到具有这两个值的相同的对象(

我有一个linq语句,看起来像这样:

if(items.Any(x => x.CustomerID == 4))
{

}
但是,我希望在项目列表中找到一个对象,该对象不仅包含customerID为4,还包含designID为6

我知道我能做到:

if(items.Any(x => x.CustomerID == 4) && items.Any(x => x.DesignID == 6))
{

}

但这可能不起作用,因为我需要找到具有这两个值的相同的对象(这将单独检查是否存在这些值)。有没有一种方法可以组合这些条件?

您可以组合两个条件,如
x.CustomerID==4和&x.DesignID==6

if(items.Any(x => x.CustomerID == 4 && x.DesignID == 6))