Why are C# arrays covariant and what benefits does it bring?

前端 未结 3 1234
终归单人心
终归单人心 2021-01-12 05:48

I\'m having trouble understanding why arrays in C# are covariant and what benefits this covariance can bring. Consider the following trivial code example:

ob         


        
3条回答
  •  旧巷少年郎
    2021-01-12 06:30

    Eric Lippert has a writeup about this (Actually a long series about 'variance', 11 parts I think)

    http://blogs.msdn.com/b/ericlippert/archive/2007/10/17/covariance-and-contravariance-in-c-part-two-array-covariance.aspx

    And some more interesting stuff

    http://blogs.msdn.com/b/ericlippert/archive/2009/09/24/why-is-covariance-of-value-typed-arrays-inconsistent.aspx

提交回复
热议问题