Understanding Covariant and Contravariant interfaces in C#

后端 未结 2 2101
我在风中等你
我在风中等你 2020-11-22 17:13

I\'ve come across these in a textbook I am reading on C#, but I am having difficulty understanding them, probably due to lack of context.

Is there a good concise exp

2条回答
  •  孤街浪徒
    2020-11-22 17:43

    This post is the best I've read on the subject

    In short, covariance / contravariance /invariance deals with automatic type casting (from base to derived and vice-versa). Those type casts are possible only if some guarantees are respected in terms of read / write actions performed on the casted objects. Read the post for more details.

提交回复
热议问题