Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EqualityComparer is missing?

Tags:

c#

.net-4.0

enter image description here

Ive seen example of :

  int[] a1 = { 1, 2, 3 };
  int[] b1 = { 1, 2, 3 };

a1.Equals(b1) //false

a1.Equals(b1,EqualityComparer<int>.Default)); //true

However I cant get the overloaded method as you see...

what am i missing ?

like image 252
Royi Namir Avatar asked Feb 22 '23 18:02

Royi Namir


1 Answers

There's no such method on System.Object(or any other type that would allow such use on an array of ints). I think you're looking for Enumerable.SequenceEqual method, an extension-method from LINQ to Objects:

a1.SequenceEqual(b1, EqualityComparer<int>.Default)

although you might as well equivalently do:

a1.SequenceEqual(b1)

EDIT: If you want to use the Equals method from IStructuralEquatable, you'll have to cast to the interface since arrays implement this interface explictly:

((IStructuralEquatable)a1).Equals(b1, EqualityComparer<int>.Default)
like image 67
Ani Avatar answered Feb 24 '23 06:02

Ani