locked
Generic Type in IEnumerable RRS feed

  • Question

  • Hello,

    I have the following:

    public class YSeries {
      public IEnumerable<T> Data { get; set; }
    }

    I would like to define the Data as Int type or Double type, or ...

    But I get the error:

    The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)

    What is the best way to do this?

    Thank You,

    Miguel

    Friday, October 12, 2012 10:58 PM

Answers

  • You need to make the containing class generic:

    public class YSeries<T> {
      public IEnumerable<T> Data { get; set; }
    }

    It will then hold whatever type it uses.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by MDMoura Friday, October 12, 2012 11:59 PM
    Friday, October 12, 2012 11:10 PM