daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Dec 18th, 2017 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int[] arr1 = {1, 2, 3, 4, 5}; // {1, 2, 3, 4, 5}
  2. int[] arr2 = {1, 2}; // {1, 2}
  3. int[] sumArr12 = arr1.Select((value, index) => value + arr2[index % arr2.Length]).ToArray(); // {2, 4, 4, 6, 6}
  4.    
  5. int[] arrOne = { 1, 2, 3, 4, 5 };
  6. int[] arrTwo = { 1, 2 };          
  7.  
  8. int[] result = new int [arrOne.Length > arrTwo.Length ? arrOne.Length : arrTwo.Length];
  9. var firstIndex = 0;
  10. var secondIndex = 0;
  11.  
  12. for(int index = 0; index < result.Length; index++)
  13. {
  14.     firstIndex = arrOne.Length > firstIndex ? firstIndex : 0;
  15.     secondIndex = arrTwo.Length > secondIndex ? secondIndex : 0;
  16.     result[index] = arrOne[firstIndex++] + arrTwo[secondIndex++];
  17. }
  18.  
  19. //result = {2, 4, 4, 6, 6}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top