A generic list of generics

Posted by SnOrfus on Stack Overflow See other posts from Stack Overflow or by SnOrfus
Published on 2010-04-23T20:36:18Z Indexed on 2010/04/23 20:43 UTC
Read the original article Hit count: 165

Filed under:
|
|

I'm trying to store a list of generic objects in a generic list, but I'm having difficulty declaring it. My object looks like:

public class Field<T>
{
    public string Name { get; set; }
    public string Description { get; set; }
    public T Value { get; set; }

    /*
    ...
    */
}

I'd like to create a list of these. My problem is that each object in the list can have a separate type, so that the populated list could contain something like this:

{ Field<DateTime>, Field<int>, Field<double>, Field<DateTime> }

So how do I declare that?

List<Field<?>>

(I'd like to stay as typesafe as possible, so I don't want to use an ArrayList).

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics