ValueTuple.Equals doesn't return true

valuetuple comparison
valuetuple distinct

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:

    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.

ValueTuple<T1,T2,T3>.Equals Method, The third one does not compile. Why does the ValueTuple implement a custom Equals method but not implement the double equals operator? share. ValueTuple.Equals does not have parameters to pass Option Strict and Option Compare, so it can't be used as the equality operator. You can compile and run the following program, and decompile it to learn the differences between Equals and the equality operator.

As you can see from source ValueTuple.Equals always returns true indeed, the same is written in docs. But (1, 2) has type ValueType<int, int> which has different Equals logic, see here.

Why do C# 7 ValueTuples implement the Equals method but not the , What does 'Space Complexity' mean? Pseudo-polynomial Algorithms · Polynomial Time Approximation Scheme · A Time Complexity Question · Searching  In value tuples, you can check if two value tuples are identical or not by using the ValueTuple.Equals Method. This method will return value which indicates whether the given ValueTuple instance is equal to the specified object or not. It will return true if the given tuples are equal, otherwise, return false.

Tuple equality is memberwise, so (1,2) == (1,2) but (1,2) != (2,1).

Check if ValueTuple instances are equal in C#, Just like all the other ValueTuple types, it supports value equality. And since it doesn't have any data, two zero-element ValueTuple s are  The ValueTuple type represents a zero-element tuple (a.k.a. nuple). It exists, even though there is no special syntax for it in C#. Just like all the other ValueTuple types, it supports value equality. And since it doesn't have any data, two zero-element ValueTuple s are always considered equals.

Question: What is the purpose of public method ValueTuple.Equals , It doesn't get automatically converted into the .Equals() method. For example, if we use the old-style Tuple(Of T1, T2) class, you get the same  However, before we code I'd like to understand why this isn't working. I assume that we are falling through all of our special cases and using the ValueTuple Equals override. If Tuples are intended to work in the way you describe, why doesn't its Equals do the job correctly? Why is it necessary to add special handling on our side?

ValueTuple.Equals issue · Issue #320 · dotnet/vblang · GitHub, As a result you don't see them being used as much as they are in other language like Python or to some extend Go (which doesn't support  ValueTuple.Equals doesn't return true Previous Strictly speaking does the scoping assignment <<- assign to the parent environment or global environment? Next How to flatten heterogeneous lists (aka tuples of tuples of …)

C# 7 ValueTuple types and their limitations, ValueTuple<…> ) uses EqualityComparer<T> , which relies on the type parameters implementation of IEquatable<T> (which only contains a  But doesn't work, and if it does work it is not gonna be efficient . Sort the list then use itertools.groupby: ValueTuple.Equals doesn't return true;

  • @RenéVogt I read in the msdn Determines whether two ValueTuple instances are equal. This method always returns true.