Compare two List<string> using LINQ

In this post, we will see how to compare two List<string> and list the elements found in one List<string> but not in the other. We will be using the Enumerable.Except method


static void Main(string[] args)
List<string> lstOne =
new List<string>() { "Jim", "Jack", "Kate", "Nope" };

List<string> lstTwo =
new List<string>() { "Jack", "Nope", "Jim" };

IEnumerable<string> lstNew = null;

// Compare two List<string> and display items of lstOne not in lstTwo
lstNew = lstOne.Except(lstTwo, StringComparer.OrdinalIgnoreCase);


static void PrintList(IEnumerable<string> str)
foreach (var s in str)




Read some more tips in my article over here Some Common Operations using List<string>

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: