foreach (DataRow row in myDataTable.Select())
foreach (DataRow row in myDataTable.AsEnumerable())
foreach (DataRow row in myDataTable.Rows)
Any differences?
Rows
isn't strongly typed - so there will be a cast on each iteration, and you can't use LINQ to objects on it easily. (I believe AsEnumerable()
will have to cast on each iteration internally as well, but at least you can use it for other LINQ methods easily.)
Select
needs to build an array, so there's obviously a performance penalty there.
Personally I'd use AsEnumerable()
unless you wanted to modify the table within the loop, in which case the fact that Select
builds an array up-front may actually be an advantage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With