TonyP
TonyP

Reputation: 5873

How to retrieve pair of columns from a DataTable as a Dictionary

I have a datatable that contains simple Key Value pair how do I return a dictionary object (DataTable.AsEnumerable().ToDictionary....

Upvotes: 2

Views: 1153

Answers (1)

SLaks
SLaks

Reputation: 887479

Like this:

var dict = DataTable.AsEnumerable().ToDictionary(
                r => r.Field<string>("KeyColumn"), 
                r => r.Field<DateTime>("ValueColumn")
);

Upvotes: 5

Related Questions