C# instantiate dictionary with tuple with values

Viewed 384

I have a dictonaty containing an int and a tuple.

I want to insert some values when instantiating, but I'm getting an error:

Cannot convert from 'System.Tuple' to 'System.Collections.Generic.IEqualtyComparer

This is what I'm trying to do:

public static readonly Dictionary<int, Tuple<int, double>> DIAMETER_METRIC_CHAMFER 
        = new Dictionary<int, Tuple<int, double>>({80, new Tuple<int, double>(16, 37.0)}
);
1 Answers

You have passed element {80, new Tuple<int, double>(16, 37.0)} into dictionary's constructor, you should use initializer instead:

public static readonly Dictionary<int, Tuple<int, double>> DIAMETER_METRIC_CHAMFER
        = new Dictionary<int, Tuple<int, double>>() 
            { 
                { 80, new Tuple<int, double>(16, 37.0) } 
            };
Related