Search code examples
c#hashtablesortedlist

Read SortedList from Hashtable


How can I read the value from SortedList when I have this structure in Hashtable ?

Below is the example

public SortedList sl = new SortedList();
sl[test] = 1;
Hashtable ht= new Hashtable();
ht.Add("root", sl);

I want to read the sl[test].


Solution

  • You just do the reverse:

    SortedList sortedList = (SortedList)ht["root"];
    
    object value = sortedList[test];