Your business logic is a bit unclear, but in regards to the Dictionary object initialization/performance issue, the solution below may serve as a valid alternative. Pertinent to your use-case, you can declare Dictionary<double, int>
as shown in the following sample C# code snippet:
public static Dictionary<double, int> SampleDictionary =new Dictionary<double, int>
{
{ 3.1, 3},
{ 3.14, 3},
{ 3.1415, 3},
{ 2.72, 2},
{ 2.728, 2}
};
It will be very fast and rather straightforward. Hope this may help.
2
solved Switch vs dictionary with double keys