Comparing 2 String Arrays and returning the matches from them in a generic list collection

I wanted to be able to compare 2 string arrays and find out which ones match. By using 2 generic lists and the FindAll method with anonymous method I was able to have it returned as a new generic list. Code is as follows:

    string[] a1 = { "One", "Two", "Three" };
     string[] a2 = { "Two", "One" };
     List l1 = new List(a1);
     List l2 = new List(a2);
     List li = l1.FindAll(delegate(string s) { return l2.Contains(s); });

Comments are closed.