Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two ordered lists with LINQ?

Tags:

c#

.net

linq

Checking equality on unordered lists can be done with Intersect, but how would you compare ordered lists with LINQ? The expression should return true if both sequences have the same elements in the same order.

Thanks

like image 334
nw. Avatar asked Jun 26 '11 00:06

nw.


1 Answers

a.SequenceEqual(b);

From the documentation:

Returns true if the two source sequences are of equal length and their corresponding elements are equal according to the default equality comparer for their type; otherwise, false.

See MSDN for more.

like image 99
agent-j Avatar answered Sep 20 '22 14:09

agent-j