jQuery and ASP.NET

March 20, 2009

Compare Two List of Strings in C# and VB.NET




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

C#


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);




VB.NET


        Dim strList1 As List(Of String) = New List(Of String)(New String() _


        {"Jack", "And", "Jill", "Went", "Up", "The", "Hill"})


 


        Dim strList2 As List(Of String) = New List(Of String)(New String() _


         {"Jack", "And", "Jill", "Went", "Down", "The", "Hill"})


 


        Dim result As Boolean = strList1.SequenceEqual(strList2)




Remember that this search is case sensitive!

'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP 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 has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

3 Responses to "Compare Two List of Strings in C# and VB.NET"
  1. Anonymous said...
    August 14, 2010 10:40 PM

    Thank You.

  2. Anonymous said...
    August 29, 2010 4:55 PM

    muchas gracias estaba buscando esto, me ha sido de mucha ayuda

  3. Saravanan said...
    September 28, 2011 6:20 AM

    I was spending more than 4 hours for this and finally solved with a simple approach. THank you so much.

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions