How I can delete a numbers from Array “a” that contained in Array “b”?
int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] b = {3, 9};
How I can delete a numbers from Array “a” that contained in Array “b”?
int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] b = {3, 9};
You cannot delete items from an array. What you can do is create another array that contains the items from a
except the items in b
and assign it to variable a
like this:
a = a.Except(b).ToArray();
You can copy b into a list, and then delete elements from it.
List<int> bList = new List<int>();
bList.AddRange(b);
foreach (int check in a)
{
if (bList.Contains(check))
{
bList.Remove(check);
}
}
b = bList.ToArray();