Share via

Tuple<int, int> Compare operator

Markus Freitag 3,791 Reputation points
2021-06-08T19:07:30.977+00:00

Hello,

if I compare two tuples always is null, why?

//What am I doing wrong?
//I have two tuples and want to compare for equality.
//Is always zero, only when I go through the list, it matches.


public Tuple<int, int> Id { get; set; }


protected readonly Tuple<int, int> m_id;
public Tuple<int, int> Id { get { return m_id; } }  



var ret = ListID.FirstOrDefault(x => x.Id == conv.Id);
ret = ListID.Where(x => x.Id == conv.Id).FirstOrDefault();

foreach (var item in ListID)
{
    if (item.Id.Item1 == conv.Id.Item1 && item.Id.Item2 == conv.Id.Item2)
    {
        ret = item;
        break;
    }
}

if (ret != null)

Thanks for tips in advance.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Answer accepted by question author

Viorel 127K Reputation points
2021-06-08T19:23:32.677+00:00

Try this:

var ret = ListID.FirstOrDefault(x => x.Id.Equals(conv.Id));

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.