Difference between object a = new Dog() vs Dog a = new Dog()

前端 未结 6 1502
野性不改
野性不改 2020-12-29 04:03
object a = new Dog();

vs

Dog a = new Dog();

In both cases a.GetType() gives Dog. Both

6条回答
  •  独厮守ぢ
    2020-12-29 04:37

    Your first line creates a variable of type object.

    The compiler won't let you treat that as a Dog.

提交回复
热议问题