Here’s the query syntax version:
DataGridViewRowCollection mydgvrs = new DataGridView().Rows;
IEnumerable<DataGridViewRow> a =
from DataGridViewRow row in mydgvrs
where row.Height > 0
select row;
which is fine, and the method syntax version:
IEnumerable<DataGridViewRow> a2 =
mydgvrs.Where(row => row.Height > 0);
which the complier rejects – “no extension method Where … could be found”?
What’s up?
Because you have the type specified in the query syntax version. (The DataGridViewRow in
from DataGridViewRow row).To translate this, you’ll need a
Cast<T>:This is required since
mydgvrsimplementsIEnumerable, but notIEnumerable<DataGridViewRow>.