Last active
January 29, 2018 18:24
-
-
Save Danielkaas94/b598332d1127e6323d2ab73659f24315 to your computer and use it in GitHub Desktop.
ArrayPlusArray in my way and as lambda expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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