Home >Backend Development >C++ >How Do Generic Covariance and Contravariance Enhance Type Safety in C# 4.0?
C# 4.0 genetic collaboration and inverter detailed explanation
C# 4.0 safely achieved genetic collaboration and inverter, solving the problems of the type of security in the previous version.
Coordination and inverter allows assignment between generic types with different types of parameters. For example, the list
is now assigned to list.
), and the inverter allows to replace the type with a super type (for example, the action
The co -changing method is particularly useful for returning more derived types for the method of returning to the base type. For example, Ienumeraable
Only allowed the search value to declare that Ienumeration does not affect the type of security.
The above is the detailed content of How Do Generic Covariance and Contravariance Enhance Type Safety in C# 4.0?. For more information, please follow other related articles on the PHP Chinese website!