Why is typeof needed?

后端 未结 6 1351
独厮守ぢ
独厮守ぢ 2021-01-12 14:57

Something I\'ve been thinking about from time to time: Why is the typeof operator needed in C#? Doesn\'t the compiler know that public class Animal is a type ju

6条回答
  •  生来不讨喜
    2021-01-12 15:04

    Well, how do you get the System.Type of a class without instantiating the class first, if you don't use the typeof operatore? Simple, you can't :D

    Since you can do a lot of reflection stuff with just a System.Type, this operator is very handy.

提交回复
热议问题