Given an interface IQuestion
and an implementation of that interface AMQuestion
, suppose the following example:
List<AMQuestion> typed = new List<AMQuestion>();
IList<IQuestion> nonTyped = typed;
This example yields, as expected, a compile error saying the two are not of the same type. But it states an explicit conversion exists. So I change it to look like this:
List<AMQuestion> typed = new List<AMQuestion>();
IList<IQuestion> nonTyped = typed as IList<IQuestion>;
Which then compiles but, at run time, nonTyped
is always null. If someone could explain two things:
- Why this doesn't work.
- How I can achieve the desired effect.
It would be greatly appreciated. Thank you!