There is also a video version of this tutorial.
Let’s understand it with example.
int[] nums1 = [1, 2, 3, 4];
int[] nums2 = [3, 4, 5, 6];
IEnumerable<int>? product = nums1.Zip(nums2, (n1, n2) => n1 * n2);
Console.WriteLine(string.Join(", ", product)); // 3, 8, 15, 24
Let’s break it down:
IEnumerable<int>? product = nums1.Zip(nums2, (n1, n2) => n1 * n2);
It takes nums1[i]
and nums2[i]
, evaluates it (nums1[0]*nums2[0]) and returns it. Here i
is the index of the array. For example.