Why not System.Void?

Posted by Stewart on Stack Overflow See other posts from Stack Overflow or by Stewart
Published on 2011-06-20T08:56:57Z Indexed on 2011/06/20 16:22 UTC
Read the original article Hit count: 176

Filed under:
|

I have no practical reason for knowing this answer, but I'm curious anyway...

In C#, trying to use System.Void will produce a compilation error:

error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object

As I understood it, void is simply an alias of System.Void. So, I don't understand why 'System.Void' can't be used directly as you might with 'string' for 'System.String' for example. I would love to read an explanation for this!

Incidentally, System.Void can be successfully used with the Mono compiler, instead of Microsoft's .Net, and there it appears equivalent to using the void keyword. This must therefore be a compiler-enforced restriction rather than a CLR restriction, right?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET