I\'m trying to make some code more readable. For Example foreach(var row in table) {...}
rather than foreach(DataRow row in table.Rows) {...}
.
The object collection in a foreach must implement System.Collections.IEnumerable or System.Collections.Generic.IEnumerable
If you have a very strong desire to enable this then you could create a wrapper class which implements IEnumerable
and has a pointer to you DataTable
. Alternatively, you could inherit DataTable
in a new class and implement IEnumerable
.
Code readability is most often personal preference. I personally find your changes to the foreach
statement less readable (but I am sure there are many on SO who agree with you).