Why C# structs do no support inheritance

Introduction

A common question asked by C# developers is why structs (the representation of .NET value types in the C# language) do not support inheritance whereas classes (.NET reference types) do?

I see three reasons:

  • Design choice
  • Conflict with array covariance
  • Memory management

As C# is the main language of the .NET platform I’ll use the term struct in this article instead of value type.

Continue reading

Objects creation in C# vs C++

Introduction

Sometimes the way two languages implement a feature can significantly differ in surprising ways, and even the keywords can be misleading.
This is the case of instantiation of C++ classes and C# structs a.k.a. .NET value types.

In this article, we will see the differences between the two languages in the way they handle the creation of objects: their memory allocation and their initialization.

Continue reading