WILT: Comparing 2 Lists in C#


I wanted to compare if 2 lists (List<T>) were equal meaning that they contained items that were equal and not that the 2 lists were actually the same object.

I made the mistake to use the Equals() method and of course got a false returned to me when I was expecting the 2 lists to be equal. The method to use is SequenceEquals() which is actually available for any class implementing IEnumerable.

SequenceEquals on MSDN

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: