Comparing Tuples with Equals method

Tuples are classes and therefore reference types.

Its Equals method is overridden to compare each individual element:


using System;


class Sample
{
    public static void Main()
    {
        var t1 = Tuple.Create(123, "Hello");
        var t2 = Tuple.Create(123, "Hello");
        Console.WriteLine(t1 == t2);  // False 
        Console.WriteLine(t1.Equals(t2));  // True
    }
}

The output:


False
True
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.