值等于一个数组什么价值?
问题描述:
只是想知道是否有检查的任何方式,如果A值等于阵列中的任何值(不使用大循环功能) - 有点像去哪儿功能
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.
例如
if (DataRow[column1value] == <any value within>Array A[])
{
//do...
}
干杯!
答
在.NET 3.5或更高版本,使用LINQ:
In .NET 3.5 or higher, using LINQ:
bool found = yourArray.Contains(yourValue);
在早期版本的框架:
bool found = Array.IndexOf(yourArray, yourValue) > -1;