Reputation: 8223
Why is the following snippet not returning the expected result?
List<string[]> data
//filling list with some values (left here out to make problem more clear)
var allRowsHavingSomeWordWithLengthGreaterThanFive = (from d in data
from c in d
where c.Length > 5
select d);
data is a List containing an array which contains strings in each row.
This statement returns null.
What am i doing wrong?
Upvotes: 0
Views: 171
Reputation: 111860
The expression is perfect as it's. I don't know why it shouldn't work.
You could make it a little easier as:
var allRowsHavingSomeWordWithLengthGreaterThanFive =
from d in data
where d.Any(q => q.Length > 5)
select d;
But I don't see why.
Perhaps the problem is that there are null
string
s or null
string[]
?
var allRowsHavingSomeWordWithLengthGreaterThanFive = (from d in data
where d != null
from c in d
where c != null && c.Length > 5
select d).ToArray();
See tester http://ideone.com/ci8zw1
Upvotes: 1
Reputation: 8223
Xanatos is right... It's about the Null values.. Should have noticed earlier. A simple null check is enough:
from d in data
from c in d
where c!=null && c.Length > 5
select d
Upvotes: 0