Compare Two List of Strings in C#

Compare Two List of Strings in C#?

Imagine you have two List. You want to quickly compare them to see if all the elements match each other. Here's how to do so:

List<string> strList1 = new List<string>
{
"Jack", "And", "Jill", "Went", "Up", "The", "Hill"
};

List<string> strList2 = new List<string>
{
"Jack", "And", "Jill", "Went", "Down", "The", "Hill"
};

bool result = strList1.SequenceEqual(strList2);

Leave a Reply