No. If you have two questions then create two threads. The last thing anyone needs is multiple, unrelated conversations in the same thread.and second question
SortedList
there. That code creates a single SortedList
object. It's not until you actually add an item that there are more SortedList
objects and there will be one for each item you add. Each of those are distinct objects so you will have to set the comparer for each one as you create and add it. If you want it to be the same each time then the logical thing to do is to write some reusable code that does just that. That's exactly what methods are for. You could write a method that received a string
key as an argument and then created a SortedList
, set the comparer and then added the new item to the existing parent SortedList
. Basically, a SortedList
is a SortedList
and you set a comparer for them all exactly the same way. There is no magic to it just because it is contained within some other data structure.SortedList<TKey,TValue>
and you want to set the Comparer
property then you need to create an object that implements IComparer<TKey>
and assign it to the property. The alternative would be to not use that class. Instead, define your own class derived from it and create an appropriate IComparer<T>
in the constructor(s). I'm not sure whether that would have any implications for the serialisation but that's why we do testing.