I realized that in the Microsoft .NET Framework the void return type is a structure. Why?
...
public void TestMethod()
{
}
...
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The framework uses a value type called
System.Voidto represent thevoidreturn type keyword for use with reflection. Althoughvoidmeans 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.ReturnTypefor an example.As to why the framework designers chose to make
System.Voida 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.