kareemborai
kareemborai

Reputation: 394

How to check equality of more than 2 collections using SequenceEqual LINQ method?

I have the following collections:

string[] names1 = { "Kareem", "Mohammed", "Borai" };
string[] names2 = { "Kareem", "Mohammed", "Borai" };
string[] names3 = { "Kareem", "Mohammed", "Borai" };

And I looking for code like this:

bool isEqual = names1.SequenceEqual(names2).SequenceEqual(names3);

How to achieve that?

Upvotes: 0

Views: 67

Answers (2)

Selman Genç
Selman Genç

Reputation: 101701

If there are more collections to check put them into another collection and use All method

bool isEqual = new [] { names2, names3, ... }.All(names1.SequenceEqual);

Upvotes: 1

har07
har07

Reputation: 89315

How about using simple && operator :

bool isEqual = names1.SequenceEqual(names2) && names1.SequenceEqual(names3);

Upvotes: 5

Related Questions