Skip to content

Instantly share code, notes, and snippets.

@Danielkaas94
Last active January 29, 2018 18:24
Show Gist options
  • Save Danielkaas94/b598332d1127e6323d2ab73659f24315 to your computer and use it in GitHub Desktop.
Save Danielkaas94/b598332d1127e6323d2ab73659f24315 to your computer and use it in GitHub Desktop.
ArrayPlusArray in my way and as lambda expression
private static int ArrayPlusArray(int[] arr1, int[] arr2)
{
int preSum1 = 0;
int preSum2 = 0;
for (int i = 0; i < arr1.Length; i++)
{
if (arr1[i] > 0)
{
preSum1 += arr1[i];
}
else
{
preSum1 += arr1[i];
}
}
for (int i = 0; i < arr2.Length; i++)
{
if (arr2[i] > 0)
{
preSum2 += arr2[i];
}
else
{
preSum2 += arr2[i];
}
}
return preSum1 + preSum2;
}
public static int ArrayPlusArray2(int[] arr1, int[] arr2)
{
return arr1.Sum(x => x) + arr2.Sum(x => x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment