Last active
October 8, 2020 11:29
-
-
Save ArisAgnew/35f8d5462ce1c12a5c423f016e2d4ea4 to your computer and use it in GitHub Desktop.
Invariance, Contravariance, Covariance C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class HightTier { } | |
internal class MediumTier : HightTier { } | |
internal class LowTier : MediumTier { } | |
internal delegate Covariance TierHandler<Invariance, in Contravariance, out Covariance>(Contravariance arg); | |
/// <summary> | |
/// if 1st_op = 2nd_op | |
/// then | |
/// <in> is tantamount to Going UP (emerged from MediumTier to HightTier) | |
/// <out> is tantamount to Going DOWN (settled down to the depths from MediumTier to LowTier) | |
/// </summary> | |
class Test | |
{ | |
void Main() | |
{ | |
TierHandler<MediumTier, MediumTier, MediumTier> tierHandler1 = default; | |
TierHandler<MediumTier, HightTier, LowTier> tierHandler2 = default; | |
tierHandler1 = tierHandler2; | |
TierHandler<MediumTier, MediumTier, MediumTier> tierHandler3 = default; | |
TierHandler<MediumTier, LowTier, HightTier> tierHandler4 = default; | |
tierHandler4 = tierHandler3; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment