Anonymous Types Equals method is overridden to perform equality comparisons: - CSharp Custom Type

CSharp examples for Custom Type:Anonymous Types

Description

Anonymous Types Equals method is overridden to perform equality comparisons:

Demo Code

using System;/*from  w w w  . j ava 2 s .  c  o m*/
class Test
{
   static void Main()
   {
      var a1 = new { X = 2, Y = 4 };
      var a2 = new { X = 2, Y = 4 };
      Console.WriteLine (a1 == a2);         // False
      Console.WriteLine (a1.Equals (a2));   // True
   }
}

Result


Related Tutorials