Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value equal to ANY value in an array?

Tags:

arrays

c#

just wondering if there is any way of checking if Value A is equal to ANY value within an array (without using large loop functions) - sort of like a "Where" function.

e.g.

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

Cheers!

like image 943
David Archer Avatar asked Nov 30 '22 06:11

David Archer


1 Answers

In .NET 3.5 or higher, using LINQ:

bool found = yourArray.Contains(yourValue);

In earlier versions of the framework:

bool found = Array.IndexOf(yourArray, yourValue) > -1;
like image 190
LukeH Avatar answered Dec 08 '22 11:12

LukeH