Sunday, December 4, 2011

How to get the difference between two string lists

Here is the source code to get difference between two string lists


        protected void check()
        {
            List<string> l1 = new List<string>();
            List<string> l2 = new List<string>();
            l1.Add("Maths");
            l1.Add("Biology");
            l2.Add("Physic");
            l2.Add("Maths");
            l2.Add("Biology");
            l2.Add("Chemistry");

            List<string> diff = l2.Except(l1).ToList();
            for (int i = 0; i < diff.Count; i++)
            {              
                Response.Write(diff[i].ToString()+"</br>");
            }
        }

I have the following result

Physic
Chemistry

Hope this helps!

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews