日期:2014-05-16  浏览次数:20741 次

为什么ArrayList is List这句话会编译失败?
如果我写:

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ArrayList is IList);
        }
    }

会有编译的问题: error CS0118: 'System.Collections.ArrayList' is a 'type' but is used like a 'variable'

看起来,一个类型的名字不能用于比较? typeof(T)关键字用于精确比较一个对象的GetType()是不是等于T;
换句话说,我想直接用类名来做"is a"判断,可以吗? 为什么呢?
------解决方案--------------------
typeof(IList).IsAssignableFrom(typeof(ArrayList));
------解决方案--------------------
 Console.WriteLine(new ArrayList() is IList);