Unmanaged constructed types
Before digging into this new C# feature, it is necessary to understand the subject by analyzing the definitions of unmanaged and constructed types cited by the language specifications:
- A type is called
constructed
if it is generic and the type parameter is already defined. For example,List<string>
is a constructed type whileList<T>
is not. - A type is called
unmanaged
when it can be used in an unsafe context. This is true for many built-in basic types. The official documentation includes the list of these types:sbyte
,byte
,short
,ushort
,int
,uint
,long
,ulong
,char
,float
,double
,decimal
,bool
,enums
,pointers
, andstruct
.
An example of an unmanaged constructed type that it was not possible to declare before C# 8 is as follows:
struct Header<T> { T Word1; T Word2; T Word3; }
The two main advantages of allowing generic structs to be unmanaged...