You can create your own method that searches for close values ββand takes two parameters: a dictionary that contains values ββand float, which are used to store the maximum search range:
static Dictionary<string, float> FindRange(Dictionary<string, float> dict, float precision) { Dictionary<string, float> temp = new Dictionary<string, float>(); List<int> counter = new int[dict.Count].ToList(); float[] values = dict.Values.ToArray(); for (int i = 0; i < values.Length; i++) for (int i2 = 0; i2 < values.Length; i2++) if (i2 != i && Math.Abs(values[i] - values[i2]) < precision) counter[i]++; for (int i = 0; i < values.Length; i++) if (Math.Abs(values[i] - values[counter.IndexOf(counter.Max())]) < precision) temp.Add(dict.FirstOrDefault(kv => kv.Value == values[i]).Key, values[i]); return temp; }
Usage example:
static void Main() { Dictionary<string, float> heights = new Dictionary<string, float>() { {"first", 61.456f}, {"second", 80.567f}, {"third", 62.456f}, {"4", 59.988f}, {"5", 90.34f}, {"6", 82.123f} };
Exit:
first 61,456 third 62,456 4 59,988
source share