Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.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

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 - Fatal编程技术网

C# 数的存在性

C# 数的存在性,c#,linq,C#,Linq,给定一个整数数组 [1,2,3,4,1] 最简单的方法是什么来知道哪里有1个可能的linq?使用: 如果数组中存在该数字,则返回true。在上面的代码中,您可以用您想要比较的int变量替换值1 使用 int[] x = { 1, 2, 3, 4 }; bool y = x.Contains(1); 任何 当数组上存在1时,isExists将返回true 试试这个: bool exists = [1,2,3,4,1].Contains(1); int[] array = { 1, 2, 3,

给定一个整数数组

[1,2,3,4,1]
最简单的方法是什么来知道哪里有1个可能的linq?

使用:

如果数组中存在该数字,则返回true。在上面的代码中,您可以用您想要比较的int变量替换值1

使用

int[] x = { 1, 2, 3, 4 };
bool y = x.Contains(1);
任何

当数组上存在1时,isExists将返回true

试试这个:

bool exists = [1,2,3,4,1].Contains(1);
int[] array = { 1, 2, 3, 4, 1 };
bool contains = array.Contains(1);

您可以使用以下代码进行检查:

Array.Find(YourArray, element => element==1);

希望这会有所帮助。

+1对于唯一不需要Lambda表达式的答案,请使用最简单、最直接的方法
int[] array = { 1, 2, 3, 4, 1 };
bool contains = array.Contains(1);
Array.Find(YourArray, element => element==1);