C# void type- safety

前端 未结 5 1851
眼角桃花
眼角桃花 2021-02-10 04:24

I am just new for C# programming (coming from C++)

My question is: In C# every type inherits from Object Why \'void\' doesn`t?Can it cause some RT/type safety problems

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 04:40

    Void is not a type of object. It's a type of nothing. At least in C#, just about the only time you use the word void is as a function return type, so it means the function returns nothing. Non-existence of something can't derive from anything. The only other place to use it is in unsafe context, referring to pointers, which also do not derive from Object.

提交回复
热议问题