我有以下接口:通行證繼承接口的方法
public interface IBase
{
int id1 { get; set; }
}
public interface IDerived : IBase
{
int id2 { get; set; }
}
而下面的(樣品)程序:
class Program
{
static void Main(string[] args)
{
IList<IDerived> derived = null;
Check(derived);
}
static void Check(IList<IBase> base)
{
}
}
我得到這個compliation錯誤: 不能轉換從'System.Collections.Generic.IList<IDerived>
'到'System.Collections.Generic.IList<IBase>
'
如果我只想傳遞一個實例,而不是一個列表,它工作,所以我在這裏錯過了什麼?
感謝,
是不是'基地'保留在C#中的關鍵字? – aolde 2009-09-08 20:37:12
沒有一個星期過去了,因爲有人不問關於協方差的問題。 – 2009-09-08 22:21:01