Cast/Convert IEnumerable to IEnumerable?

前端 未结 6 2046
我在风中等你
我在风中等你 2021-01-04 08:48

The following complies but at run time throws an exception. What I am trying to do is to cast a class PersonWithAge to a class of Person. How do I do this and what is the wo

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-04 09:36

    Make PersonWithAge inherit from Person.

    Like this:

    class PersonWithAge : Person
    {
            public int Age { get; set; }
    }
    

提交回复
热议问题