`

myth buster - typeof accepting array of types not acceptable

    博客分类:
  • C#
c# 
阅读更多

I have seen from some book where this kind of code has been given.

Type[] types = typeof(TypeA, TypeB);

whether it is some new feature that has y et to be supported now, or is it somehting that is typo from the original books...
Let's give a try, and below is the test result.

    class TypeA
    { }

    class TypeB
    {
    }

    class Program
    {
        static void Main(string[] args)
        {
            Type[] types = typeof(TypeA, TypeB);
            if (types.Length > 0)
            {
                Console.WriteLine("syntax type(ypeA, TypeB) is OK");
            }
            else
            {
                Console.WriteLine("syntax type(TypeA, TypeB) is not OK");
            }
        }
    }

 while, the code stop to compile in the first place. so the myth-buster, typeof can accept more than one type as arguments - proven false. 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics