allNodes[0] will not give you the first element in the dictionary - it will give you an element with a key value of float 0 .
If you want the first element to try using allNodes.Values.First() . Or to find the first key, use allNodes.Keys.First()
To delete items one at a time, loop a copy of the Keys collection and call allNodes.Remove(key);
foreach (var key in allNodes.Keys.ToList()) { allNodes.Remove(key); }
To answer your addition to your question, yes SortedDictionary (any flavor of the Dictionary , for that matter) will not handle duplicate keys - if you try to add an item with an existing key, it will overwrite the previous value.
You can use SortedDictionary<float, List<Node<T>>> , but then you have the difficulty of retrieving collections compared to elements that need to initialize each list, and not just add an element, etc. This is all possible and may be the fastest structure to add and receive, but it adds a bit of complexity.
D Stanley
source share