how to do a dictionary reverse lookup

Use the Linq ToDictionary function:

var reversed = d.ToDictionary(x => x.Value, x => x.Key);

You can see below that it works, as tested in Linqpad:

var d = new Dictionary<int, string>();
d.Add(1,"one");
d.Add(2,"two");
d.Dump(); //prints it out in linq-pad
var reversed = d.ToDictionary(x => x.Value, x => x.Key);
reversed.Dump(); //prints it out in linq-pad

Prints

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)