Map two lists into a dictionary in C#

With .NET 4.0 (or the 3.5 version of System.Interactive from Rx), you can use Zip():

var dic = keys.Zip(values, (k, v) => new { k, v })
              .ToDictionary(x => x.k, x => x.v);

Leave a Comment