Sukhdevsinh Zala
Sukhdevsinh Zala

Reputation: 1215

cannot create a SortedList having another SortedList

SortedList<int, string> months = new SortedList<int, string>();
SortedList<int, SortedList> all = new SortedList<int, SortedList>();

i want to create a SortedList which contains another sorted list of type of 'months' as in the above code snippet.

months.Add(1, "January");
all.Add(2012,months);

i get error

cannot convert from 'System.Collections.Generic.SortedList' to 'System.Collections.SortedList'

m confused...

Upvotes: 0

Views: 119

Answers (2)

Mario
Mario

Reputation: 36527

You'll have to name your parameters (otherwise it's a different type). Try this:

SortedList<int, SortedList<int, string> > all = new SortedList<int, SortedList<int, string> >(); 

Upvotes: 0

Matti Virkkunen
Matti Virkkunen

Reputation: 65156

You forgot to specify the type arguments for the inner SortedList, and it found a non-generic one, which is a different type. Do this:

var all = new SortedList<int, SortedList<int, string>>();

Upvotes: 3

Related Questions