What does default(object); do in C#?

后端 未结 9 2325
误落风尘
误落风尘 2020-11-28 03:03

Googling is only coming up with the keyword, but I stumbled across some code that says

MyVariable = default(MyObject);

and I am wondering

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 03:35

    It will set the default value of an object to a variable: null for reference types and 0 for value types.

提交回复
热议问题