@ahmed salah , Welcome to Microsoft Q&A, you could refer to the following code to get difference between two array without using linq.
Code:
static void Main(string[] args)
{
string[] arr1 = { "Watermelon", "Apple", "Mango", "Guava", "Banana" };
string[] arr2 = { "Orange", "Kiwi", "Apple", "Watermelon" };
List<string> result = new List<string>();
GetList(arr1, arr2, result);
GetList(arr2, arr1, result);
foreach (var item in result)
{
Console.WriteLine(item);
}
Console.WriteLine();
}
static void GetList(string[] arr1, string[] arr2,List<string> result)
{
foreach (string tmp in arr1)
{
bool existsInB = false;
foreach (string tmp2 in arr2)
{
if (tmp == tmp2)
{
existsInB = true;
break;
}
}
if (!existsInB)
{
result.Add(tmp);
}
}
}
Result:
Hope the above code could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.