![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Inheriting from a SortedList
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 |
|
|||
|
Re: Inheriting from a SortedList
Venkatesh Reddy <venkatesh.reddy@pinerivercapital.com> wrote:
> 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). -- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet World class .NET training in the UK: http://iterativetraining.co.uk |
|
|||
|
Re: Inheriting from a SortedList
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. "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message news:MPG.21ca313ca555f246eb@msnews.microsoft.com.. . > Venkatesh Reddy <venkatesh.reddy@pinerivercapital.com> wrote: >> 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). > > -- > Jon Skeet - <skeet@pobox.com> > http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet > World class .NET training in the UK: http://iterativetraining.co.uk |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|