Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Void a structure?

Tags:

c#

.net

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

...
public void TestMethod()
{

}
...
like image 827
farid bekran Avatar asked Jul 16 '12 05:07

farid bekran


People also ask

What is a 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.

What are voids in solid state?

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.

What are triangular voids in 2 dimensional structures?

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

What is a void block in Minecraft?

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.


1 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.

like image 76
BoltClock Avatar answered Oct 06 '22 19:10

BoltClock