Why is Void a structure?

I realized that in the Microsoft .NET Framework the void return type is a structure. Why?

...
public void TestMethod()
{

}
...

Answers


The framework uses a value type called System.Void to represent the void return type keyword for use with reflection. Although void means the lack of a return value, it's still technically a type, and in order for it to be expressed as such in code it has to be either a structure (value type) or a class (reference type).

See MethodInfo.ReturnType for an example.

As to why the framework designers chose to make System.Void a structure and not a class is anybody's guess, but it has to be represented by a type in the first place. I'd agree with the comments that it's to avoid the unnecessary overhead typically associated with reference lookups, among other optimizations.


Need Your Help

How to detect Rails environment inside whenever

ruby-on-rails ruby-on-rails-3 cron rake whenever

This question will probably only make sense if you know about the whenever gem for creating cron jobs.

On zoom event for google maps on android

java android events google-maps zoom

We're building an application which is using the google maps api for android.