Home >Backend Development >C++ >How Does C# 4.0's Covariance and Contravariance Revolutionize Generic Programming?
C# 4.0 coordination and inverter: the transformation of the programming paradigm
After PDC 2008, C# 4.0 announced that it supports genetic collaboration and inverting, which has attracted widespread attention in the software development community. These concepts have been considered to be unreasonable in C#, and now they are about to change the way developers handle generic programming.
C# 4.0 square difference
In contrast to the previous concerns about the security of code security, the realization of the difference between the opponent of C# 4.0 is designed to maintain type security. It only supports the interface and commission, and requires the use of "in" (inverter) and "out" (collaborative) keywords to explicitly declare the type parameters.
The practical application of the coordinated change
Xiechang allows the derived type to be assigned to the base type. For example, List can be assigned to List . This is especially useful when the value of different generic parameters is returned.
The actual application of the inverter
, because any method of accepting object parameters can handle the string parameters without problems.
The above is the detailed content of How Does C# 4.0's Covariance and Contravariance Revolutionize Generic Programming?. For more information, please follow other related articles on the PHP Chinese website!