List
MSDN声明:
public class List<T> : IList<T>, ICollection<T>,
IEnumerable<T>, IList, ICollection, IEnumerable
反射器给出了类似的图片.List
真的实现了所有这些吗(如果是,为什么)?
interface I1 {}
interface I2 : I1 {}
interface I3 : I2 {}
class A : I3 {}
class B : I3, I2, I1 {}
static void Main(string[] args)
{
var a = new A();
var a1 = (I1)a;
var a2 = (I2)a;
var a3 = (I3)a;
var b = new B();
var b1 = (I1) b;
var b2 = (I2)b;
var b3 = (I3)b;
}
它编译.
[更新]:
伙计们,据我所知,所有的回复都是:
class Program
{
interface I1 {}
interface I2 : I1 {}
interface I3 : I2 {}
class A : I3 {}
class B : I3, I2, I1 {}
static void I1M(I1 i1) {}
static void I2M(I2 i2) {}
static void I3M(I3 i3) {}
static void Main(string[] args)
{
var a = new A();
I1M(a);
I2M(a);
I3M(a);
var b = new B();
I1M(b);
I2M(b);
I3M(b);
Console.ReadLine();
}
}
将给出错误,但它编译和运行时没有任何错误.为什么?