Reputation: 15108
I have this which check for datarows which match an expression:
DataRow[] foundRows = this.callsTable.Select(searchExpression);
How do i check if it returns some datarows, so basically if it returns none don't do what's in the if function?
I have tried:
if (foundRows != null) { }
Upvotes: 4
Views: 8850
Reputation: 4638
check the length of the array like this
if (foundRows.Length > 0)
{
//Your code here
}
or you can check with Count() too
if (foundRows.Count() > 0)
{
//Your code here
}
Upvotes: 0
Reputation: 5341
You can use the Count method to verify:
if (foundRows.Count() == 0)
Upvotes: 1
Reputation: 28107
You can do the following with LINQ
var areThereAny = foundRows.Any();
var count = foundRows.Count();
If you only want to find out whether there are any rows that match your condition, you can do the following:
var anyThatMatch = this.callsTable.Any(selectCondition);
Upvotes: 0
Reputation: 148110
You can use the Length
property of array to check if you get any rows
if (foundRows.Length == 0)
Upvotes: 9