views:

33

answers:

1

How to convert DataTable having N rows into KeyValuePair<long,string>[] type having same N no of rows

I want to return KeyValuePair<long,string>[] kind of value from a function that will convert DataTable into above type.

+1  A: 
return table.AsEnumerable()
    .Select(r => new KeyValuePair<long, string>(r.Field<long>("longFieldName"), r.Field<string>("stringFieldName")))
    .ToArray();
Toby
You mean .ToArray() - and it's worth mentioning that the long column may not be null.
Eamon Nerbonne
Thanks, I got ahead of myself there. D'oh.
Toby