For example, enumerable.ToList()
versus list.AsReadOnly()
.
I ask because I've got a class that turns an IEnumerable<T>
into an IDataReader
. I wonder whether the extension method that creates it should be ToDataReader
or AsDataReader
.
As*
methods return a different interface without iterating the source, while To*
iterates over it and creates a new object.
In your case, AsDataReader
should be the right choice, as you don't iterate over the source when creating the DataReader
, but only when the user calls methods on it.
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