Introduction to Generics:
C#2.0 the introduction of generic mechanism, it realizes the parameterization of the type and method, that is, the type becomes the logical reuse of the parameters, and a large number of type security checks are transferred from runtime to compile time, which improves the speed of code running.
Benefits of Generics:
1) Type safety
When we use generic types or generic methods to manipulate a specific data type, the compiler will ensure that these generic types or generic methods only apply to objects that are compatible with that data type, otherwise the compiler would have an error.
2) Improve performance
If there is no generic mechanism, we need to use the object type as either a parameter or a return value type, which requires a forced type conversion, and when we manipulate the object is a value type, we will need to box and unboxing the operation. After introducing a generic mechanism, we can manipulate the type by creating a generic type or generic method, eliminating the need for a forced type conversion, eliminating the need for type safety checks at run time, and eliminating the need for boxing and unpacking when manipulating value types, which improves code performance
Generic type
The generic mechanism provided by the C # language is mainly divided into
Generic types (generic types include: classes, interfaces, delegates, and structs) and generic methods
Type constraints and type inference in generics for generic interface generic delegate generic methods
C # note--2. Generics