I realized that in the Microsoft .NET Framework the void
return type is a structure. Why?
...
public void TestMethod()
{
}
...
A structure void is an invisible block that allows existing blocks to remain unchanged rather than be overridden when using the structure block to load a structure.
Voids In Solid State Voids literally mean gaps between the constituent particles. Voids in solid states mean the vacant space between the constituent particles in a closed packed structure. Close packing in solids can be generally done in three ways: 1D close packing, 2D close packing and 3D close packing.
In 2 dimensional structures when the atoms are arranged in square close packing and hexagonal close packing, we see empty spaces left over between the atoms. These empty spaces are called voids and in the case of hexagonal packing, these voids are in triangular shapes and are known as the triangular voids. Packing of Spheres in 2 dimension
Structure Void A structure void is an invisible block that allows existing blocks to remain unchanged rather than be overridden when using the structure block to load a structure.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With