我有这样的方法...C#接口作为参数类型转换问题
public static IList<IOutgoingMessage> CompressMessages(IList<IOutgoingMessageWithUserAndPtMedInfo> msgs)
{
StoreOriginalMessages(msgs);
...
}
它调用这个方法...
private static void StoreOriginalMessages(IList<IOutgoingMessage> msgs) {...}
和IOutgoingMessageWithUserAndPtMedInfo
定义像这样...
public interface IOutgoingMessageWithUserAndPtMedInfo: IOutgoingMessage
{
IPatientMedication PatientMedication { get; set; }
IUserContainer User{ get; set; }
}
我在尝试从我的CompressMessages
方法中调用StoreOriginalMessages
方法时出现此错误:
不能转换从 'System.Collections.Generic.IList <MyMediHealth.DataAccess.Containers.IOutgoingMessageWithUserAndPtMedInfo>
' 到 'System.Collections.Generic.IList <MyMediHealth.DataAccess.Containers.IOutgoingMessage>
'
不明白为什么。我希望它会接受它,因为IOutgoingMessageWithUserAndPtMedInfo
继承自IOutgoingMessage
。
我在做什么错?
我在3.5工作,所以标记为答案。谢谢! – Marvin 2011-06-14 15:15:29