2

I cant wrap my head around why I cant call a method with this signature:

public void Test(Tuple<int, IEnumerable<string>> x);

like that:

Test(Tuple.Create(4, new List<string>()))

I think this has to do with co/contravariance but thats just a guess. Can somebody share his cleverness?

Christoph
  • 26,519
  • 28
  • 95
  • 133

1 Answers1

4

Yes, the Tuple class is not marked as co- or contravariant, the reason being only interfaces can be co- or contravariant. So the type parameters have to match exactly. Here's the reason why classes can't be co- and contravariant.

Community
  • 1
  • 1
Tim Rogers
  • 21,297
  • 6
  • 52
  • 68