Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int[] arr1 = {1, 2, 3, 4, 5}; // {1, 2, 3, 4, 5}
- int[] arr2 = {1, 2}; // {1, 2}
- int[] sumArr12 = arr1.Select((value, index) => value + arr2[index % arr2.Length]).ToArray(); // {2, 4, 4, 6, 6}
- int[] arrOne = { 1, 2, 3, 4, 5 };
- int[] arrTwo = { 1, 2 };
- int[] result = new int [arrOne.Length > arrTwo.Length ? arrOne.Length : arrTwo.Length];
- var firstIndex = 0;
- var secondIndex = 0;
- for(int index = 0; index < result.Length; index++)
- {
- firstIndex = arrOne.Length > firstIndex ? firstIndex : 0;
- secondIndex = arrTwo.Length > secondIndex ? secondIndex : 0;
- result[index] = arrOne[firstIndex++] + arrTwo[secondIndex++];
- }
- //result = {2, 4, 4, 6, 6}
Add Comment
Please, Sign In to add comment