0

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};
Harardin
  • 55
  • 6
  • you can see something similar here [link](http://stackoverflow.com/questions/5058609/how-to-perform-set-subtraction-on-arrays-in-c) – Catalin Jul 30 '16 at 21:25

2 Answers2

5

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();
Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62
0

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();
Robert Columbia
  • 6,313
  • 15
  • 32
  • 40