When using reflection Type.IsPrimitive
on a void
type returns false.Coming from a C++ background this was surprising.
Looking at the C# 6.0 spe
Why isn't void a primitive type? Because it isn't something you can instantiate. It isn't a primitive type, nor a reference type. It is nothing at all.
Eric Lippert describes some 'problems' with the void type in this post on Software Engineering, which goes into the specifics of void
as a type to use in delegates and Action
s:
A type system is essentially a system for making logical deductions about what operations are valid on particular values; a void returning method doesn't return a value, so the question "what operations are valid on this thing?" don't make any sense at all. There's no "thing" for there to be an operation on, valid or invalid.
Making it a primitive type defeats the special meaning and purpose of void
in the VES (Virtual Execution System), as Eric explains later on:
The effect of a call to a void method is fundamentally different than the effect of a call to a non-void method; a non-void method always puts something on the stack, which might need to be popped off. A void method never puts something on the stack.
Making void
a primitive type breaks this rule, although you could argue its usefulness, as Eric explains further in the post referenced.