Common Type System—Value Construction


Jump to: navigation, search
Visual C# Tutorials
.NET Framework Tutorials

Common Type System

© 2006 Wiley Publishing Inc.

Value Construction

Because value types are allocated inline, their default initialization is to zero-out all of their bits without even calling a constructor. This is extremely efficient, avoiding the need to make essentially a method call for each value instantiation. For this reason, C# prohibits creating parameterless constructors for structs. This avoids confusion with the statement new YourValueType(), which is actually compiled into IL that creates a new zeroed out chunk of bits. In C#, you cannot guarantee that value type creation will go through one of your constructors, although this is not entirely obvious immediately.



Previous_Page_.gif Next_Page_.gif





Personal tools
Share this page