ValueTuple.Equals doesn't return true

  • A+

Given what is written in the documentation ( ) it seems that ValueTuple.Equals should always return true

Does it mean it will return true even if the tuples have different value in their fields?

I'm trying to test it but I cannot hit the Console.Writeline with this simple code:

if((1,2).Equals((2,1))) {     Console.WriteLine("It's true"); } 

Is there any caveat I should be aware of?

I've tested with c# versions from 7.0 to 7.3

You are reading documentation of non-generic ValueTuple. This one has no fields and represents an "empty" ValueTuple, so of course one empty tuple is always equal to another empty tuple.

In your example code you are using generic ValueTuple<T1, T2>, and this documentation article is not related to it. Here is relevant Equals method documentation.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: