How to return the difference of a C# matrix without using LINQ?

Asked

Viewed 56 times

1

I have a matrix A and B:

Method:

public static int[] RetornaDiferenca(int[] a, int[] b)
{...
}

Calling the method:

RetornaDiferença(new int[] {1, 2, 2}, new int[] {2})

The result would have to be: new int[] {1} as all items of 'b' must be removed from 'a'

How To Do It Without?

[Edited] Another detail:

RetornaDiferença(new int[] {1, 2, 2}, new int[] {1})

The return has to be:

int[] {2,2} 
  • Is there something you’ve tried? Why can’t you use LINQ? This description looks a lot like course/college exercise.

  • Linq makes it much easier, so I ask how to do it without using it. Ah, it’s nothing college - just practicing it yourself.

  • 2

    It’s probably just exercise restriction, but I don’t think it’s too wide. Anyway: https://dotnetfiddle.net/KSL1pU I remembered the college days

  • you need 2 loop , 1 to traverse B and for each item of B to traverse A and remove identical elements of B in A. and return A simple like this.

  • and RetornaDiferença(new int[] {1, 2, 2}, new int[] {2,3}) what would be the return ?

  • It would be: new[] {1};

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.