Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using linq on TableRowCollection

Tags:

asp.net

linq

I have an AspTable with a small number of rows. I want to run a linq Where() on the collection to find one and remove it.

mytable.Rows is of type TableRowCollection mytable.Rows.AsQueryable() says it returns a Linq.Queryable but intellisense on this does not give me my Linq operators.

like image 907
Dustin Getz Avatar asked Mar 01 '23 04:03

Dustin Getz


1 Answers

You should be able to use:

myTable.Rows.Cast<TableRow>()

The problem is that TableRowCollection implements IEnumerable, but not IEnumerable<T> - and it's the latter that LINQ to Objects works with, primarily. The above will create an IEnumerable<TableRow> which will basically cast each item in turn.

like image 198
Jon Skeet Avatar answered Mar 11 '23 19:03

Jon Skeet