I am trying to return this collection in a function:
List<string> codes = ( from q in Data.AsEnumerable() select q.Field<string>("START") );
return codes;
This throws error:
Cannot implicitly convert type 'System.Data.EnumerableRowCollection<string>' to 'System.Collections.Generic.List<string>'
What's the best way to return such a collection?
Since EnumerableRowCollection<TRow> implements IEnumerable<T>
you can just add a ToList()
at the end:
using System.Linq;
List<string> bankCodes = ( from q in QueueData.AsEnumerable() select q.Field<string>("START") ).ToList();
or alternatively
List<string> bankCodes = QueueData.AsEnumerable()
.Select(r => r.Field<string>("START"))
.ToList();
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