Reverse a dictionary

Have you ever wished your dictionary of <K,V> was in fact of <V,K>? I might be the last person to figure this out, but with LINQ (and a couple lambdas) you can do this with one magical line of code:

var newDict = oldDict.ToDictionary(l => l.Value, l => l.Key);

Neat, eh?

1 Comment

  • At 2008.09.22 15:48, Rab said:

    You’re not the last to figure it out.

    (Required)
    (Required, will not be published)