A value equal to ANY value in the array?

just wondering if there is a way to check if the value of A is equal to ANY value inside the array (without using the large loop functions) - sort of like the Where function.

eg.

if (DataRow[column1value] == <any value within>Array A[])
{
//do...
}

Hurrah!

+3
source share
5 answers

In .NET 3.5 or higher, using LINQ:

bool found = yourArray.Contains(yourValue);

In earlier versions of the structure:

bool found = Array.IndexOf(yourArray, yourValue) > -1;
+13
source
if(myArray.Contains(A)){...}
+8
source
yourArray.Any(item => item != null && item.Equals(yourvalue));
0

Array.Contains

.

,

int[] array = new int[] { 1, 2, 3, 4, 5 };
if (array.Contains(5))
{
}
0

, IndexOf(), ,

0

Source: https://habr.com/ru/post/1724309/


All Articles