Skip to content

Instantly share code, notes, and snippets.

@booyaa
Created October 7, 2013 14:33
Show Gist options
  • Save booyaa/6869007 to your computer and use it in GitHub Desktop.
Save booyaa/6869007 to your computer and use it in GitHub Desktop.
LINQmagick

Convert DataTable into a Dictionary

let's assume your dt looks like

|key |value|
|----------|
|your|mum  |

code

Dictionary<string, string> config = (from row in dt.AsEnumerable()
						  select new
						  {
							   key = row.Field<string>("key"),
							   value = row.Field<string>("value")
						  }
						  ).AsEnumerable().ToDictionary(k => k.key, v => v.value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment