C
C#3y ago
Thinker

Differing covariant arrays [Answered]

Why does this work
var xs = new string[] {};
object[] ys = xs;
var xs = new string[] {};
object[] ys = xs;
but this doesn't?
var xs = new int[] {};
object[] ys = xs;
var xs = new int[] {};
object[] ys = xs;
also idk what to name this post
5 Replies
333fred
333fred3y ago
Variance only works for reference conversions int->object is a boxing conversion
Thinker
ThinkerOP3y ago
That makes sense I think this is also the same for variance in interfaces, right?
333fred
333fred3y ago
variance period
Thinker
ThinkerOP3y ago
right
Accord
Accord3y ago
✅ This post has been marked as answered!

Did you find this page helpful?