Forbidden Void type in C#


I’ve had this come up a couple of times.  I’d really like to be able to do something like this:

Func<bool, Void> whyNot = test => Console.WriteLine(test);

This is equivalent to:

Action<bool> okThisWorks = test => Console.WriteLine(test);

Although an actual Void type exists in the .NET Framework.  There error is very specific:

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

It even calls out the C# language!  Having a first class, supported Void type helps out quite a bit in various Functional Programming scenarios I’ve run into, and I’ve always had to resort to using the Action delegates.

I’m sure there’s a good reason for the explicit forbidding here, much like the generic variance issues.  Not being on the C# team, I can’t really think of any.  Anyone else have any insight here?

Designing primary keys