Skip to content

Instantly share code, notes, and snippets.

@built
Created June 8, 2012 16:00
Show Gist options
  • Save built/2896420 to your computer and use it in GitHub Desktop.
Save built/2896420 to your computer and use it in GitHub Desktop.
Dictionary comprehension in C#
// Initial version w/ explicit types:
Dictionary<string, string> users = db.Users.Where(u => u.Account.Id == accountID).ToDictionary<User, string, string>(u => u.Id.ToString(), u => u.Login.Username);
// Without explicit type info.
var users = db.Users.Where(u => u.Account.Id == accountID).ToDictionary(u => u.Id.ToString(), u => u.Login.Username);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment