Here is another (less readable but maybe a little bit more efficient) approach that does not need LINQ:
public static int[] GetDifference(int[] first, int[] second){ int commonLength = Math.Min(first.Length, second.Length); int[] diff = new int[commonLength]; for (int i = 0; i < commonLength; i++) diff[i] = Math.Abs(first[i] - second[i]); return diff;}
Why little bit more efficient? Because ToArray
has to resize the array until it knows the final size.