Reputation: 8231
How to convert in the shortest way a list of Tuples to Dictionary (C#) ?
IList<Tuple<long, int>> applyOnTree = getTuples();
Upvotes: 27
Views: 18695
Reputation:
Assuming the long
is the key and the int
is the value;
applyOnTree.ToDictionary(x => x.Item1, x => x.Item2);
Obviously, just reverse those two if it's the other way around.
Upvotes: 47
Reputation: 9214
Use ToDictionary
extension method:
var dictionary = applyOnTree.ToDictionary(l => l.Item1, l => l.Item2);
Upvotes: 5