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
In C#, void is a keyword that is used in two contexts:
In the context of method signatures, void
indicates the absence of a return type; it doesn't refer to a type "void" which could inherit from object
.
(In reflection, a return type has always to be specified. For this reason, there is a System.Void
type in the framework, but void
and System.Void
cannot be used interchangeably.)
In unsafe context, void*
is a pointer type to an unknown type. As mentioned in the blog post linked by @Colin Mackay, pointer types do not inherit from object
, although they can be converted to one.