Inheriting from a SortedList

  • Thread starter Thread starter Venkatesh Reddy
  • Start date Start date
V

Venkatesh Reddy

Hi all -

So, basically, I want to create a class inherited from a SortedList<T1, T2>
with the types T1, T2 fixed. But the C# compiler gives me an error when I do
this:

class C : SortedList<T1, T2>
{
}

Instead, I have to do this:

class C<T1, T2> : SortedList<T1, T2>
{
}

But then, when I use the class, I have to always declare variables with type
C<T1, T2> instead of just C.

Any thoughts? I don't want other people using this class to have to bother
with the types. Maybe I am using SortedList wrong, and there is a better way
of doing what I want?

Thanks.

-- V
 
Venkatesh Reddy said:
So, basically, I want to create a class inherited from a SortedList<T1, T2>
with the types T1, T2 fixed. But the C# compiler gives me an error when I do
this:

class C : SortedList<T1, T2>
{
}

Instead, I have to do this:

class C<T1, T2> : SortedList<T1, T2>
{
}

But then, when I use the class, I have to always declare variables with type
C<T1, T2> instead of just C.

Any thoughts? I don't want other people using this class to have to bother
with the types. Maybe I am using SortedList wrong, and there is a better way
of doing what I want?

You want:

class C : SortedList<int,string>

(or whatever you want the types to be fixed as).
 
Yes, for whatever reason, I was getting an error before, and it is gone now.
Must have been related to a different bug. Sorry about that.
 
Back
Top