Wednesday 14 September 2011

Comparing Arrays(Finding Unique Values by comparing arrays)

 string[] Array1 = { "Vinay", "Pradeep", "Manoj", "Nimesh", "Sandy", "Viren", "Suresh" };
 string[] Array2 = { "Vinay", "Pradeep", "Manoj", "Nimesh", "Sandy" };

        foreach (string nextRole in Array1)
        {
            int position = Array.IndexOf(Array2, nextRole);
            if (position < 0) // change it to > if u want common values from both arrays)
            {
                Response.Write(nextRole + "<br/>");
            }
        }

========================

Output:
Viren
Suresh
===============