Inheriting from generic List

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I think I must be missing something about generics, perhaps just about the
syntax. I'd like to derive a class MyList from System.Collections.Generic so
that it can only contain instance of MyItem.

No problem with

class MyList<T> : List<T>
{
}

but that requires me to create it with MyList <MyItem> myList = new
MyList<MyItem>() and I'd like to hide that bit in the list class itself so I
could call MyList myList = new MyList();

What should the constructor look like? I think it should be something like
the illegal

class MyList : List<T>
{
public MyList() : base (<T>)
{
}
}

but it obviously isn't! Is this possible or is my understanding of generics
completely wrong?

(Anyone know a good primer on this?)

Andrew


.



Relevant Pages

  • Re: Inheriting from generic List
    ... >I think I must be missing something about generics, ... >syntax. ... >so that it can only contain instance of MyItem. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: User-defined type attributes
    ... The syntax for invoking an attribute may imply a dynamic function ... Ada's generics lack ... discriminants with it. ... does not hold since Ada 95, ...
    (comp.lang.ada)
  • A parametric objects system
    ... messaging syntax resembles that of Objective-C. ... I am aware of variety of object systems devised for Scheme ... polymorphism, ad-hoc generics, parametric datatype ... maintain any registry of classes the resulting class ...
    (comp.lang.scheme)
  • Re: Open letter to sun about java generics syntax
    ... > open/close pair of characters delimiting the type parameter list. ... I don't think the Java language syntax ... > should be designed specifically to look nice embedded in XML documents. ... Anyway, generics as they appear ...
    (comp.lang.java.programmer)
  • Re: operator new with "value type"
    ... generics... ... struct should be forced to come up with a suitable alternative syntax so that a generic class or method that has to initialize/instantiate some instance of one or more type parameters for the generic can still be done without caring whether the type is a value or reference type. ... do I have an alternative syntax? ... sure it makes much benefit to single out construction for special ...
    (microsoft.public.dotnet.languages.csharp)