In this code fragment
foreach (var row in grid.Rows) { }
the type of row is inferred as Object instead of GridViewRow. I have to explicitly declare the type to work with a GridViewRow:
foreach (GridViewRow row in grid.Rows) { }
GridView.Rows returns a GridViewRowCollection and GetEnumerator on the collection "Returns an enumerator that contains all GridViewRow objects in the GridViewRowCollection." If I access a single row from the collection by index
var row = grid.Rows[0];
the type is correctly inferred. Why can't the compiler infer the type for row in the foreach declaration?
Edited to add: Interesting responses, I didn't think to look for the obvious problem. ListView.Items implements IList<ListViewDataItem>
, so this looks like an oversight to me.