Is there a way to fill an array via a SqlDataReader (or any other C# ADO.NET object) without looping through all the items? I have a query that is returning a single column, and I want to put that into a string array (or ArrayList, or List, etc).
Share
It is possible. In .NET 2.0+,
SqlDataReaderinherits fromDbDataReader, which implementsIEnumerable(non-generic one). This means that you can use LINQ:That said, the loop is still there, it’s just hidden in
Enumerable.Select, rather than being explicit in your code.