I would recommend SortedList<double, string> . This is similar to what you want:
- Automatically sorted by
double values ββ( Keys property) - Lines are available in order through the
Values property.
This will only work if your double values ββare unique. Otherwise, you can wrap SortedList<double, List<string>> in your own collection, for example:
class DoubleStringList { SortedList<double, List<string>> _strings = new SortedList<double, List<string>>(); public void Add(string str, double value) { List<string> list; if (!_strings.TryGetValue(value, out list)) { _strings[value] = list = new List<string>(); } list.Add(str); } public IEnumerable<KeyValuePair<double, string>> GetEntries() { var entries = from entry in _strings from str in entry.Value select new KeyValuePair<double, string>(entry.Key, str); return entries; } }
source share