The C# Type System

In the .NET framework, there is a common type system that is used to allow all languages targeted at the .NET environment to interoperate with each other. C# makes use of this underlying type system. Earlier it was stated that everything in C# is an object. Well this is almost true. Primitive data types are not objects and the reason for this is performance. Because objects are allocated on the heap and managed by the GC, this would introduce a significant amount of overhead to deal with basic types such as int and char. For this reason, C# implements primitive types as structs, which are considered value types. In C#, a value type is allocated on the stack as opposed to being allocated on the heap and managed by the GC. Because ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.