Possible Duplicate:
Comparing Arrays in C#
I have a two string arrays:
string[] a;
string[] b;
How can I identify how many (and what) items of a
are not present in b
? As I am using .NET 2.0 so I can't use linq.
Just enumerate items in both a
and b
, just like in the old days:
private static void Main(string[] args)
{
string[] a = new string[] { "a", "b", "c", "d" };
string[] b = new string[] { "c", "d" };
foreach (string tmp in a)
{
bool existsInB = false;
foreach (string tmp2 in b)
{
if (tmp == tmp2)
{
existsInB = true;
break;
}
}
if (!existsInB)
{
Console.WriteLine(string.Format("{0} is not in b", tmp));
}
}
Console.ReadLine();
}