Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to zip two integer arrays and print the pairs.
C Sharp (C#)
var numbers = new[] {1, 2, 3};
var words = new[] {"one", "two", "three"};
var zipped = numbers.[1](words, (n, w) => (n, w));
foreach (var (n, w) in zipped)
{
Console.WriteLine($"{n} - {w}");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select instead of Zip will not combine two sequences.
Where filters elements but does not combine sequences.
✗ Incorrect
The Zip method combines two sequences element-wise into pairs.
2fill in blank
mediumComplete the code to zip two lists and create a dictionary from the pairs.
C Sharp (C#)
var keys = new List<string> {"a", "b", "c"};
var values = new List<int> {1, 2, 3};
var dict = keys.[1](values, (k, v) => new { k, v })
.ToDictionary(x => x.k, x => x.v); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select only projects one sequence, not combining two.
GroupBy groups elements but does not pair two sequences.
✗ Incorrect
Zip pairs elements from two sequences, which can then be converted to a dictionary.
3fill in blank
hardFix the error in the code to correctly zip two arrays and print the sum of pairs.
C Sharp (C#)
int[] arr1 = {1, 2, 3};
int[] arr2 = {4, 5, 6};
var result = arr1.[1](arr2, (x, y) => x + y);
foreach (var sum in result)
{
Console.WriteLine(sum);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select only works on one sequence.
Concat joins sequences end to end, not element-wise.
✗ Incorrect
Zip combines two sequences element-wise, allowing you to sum pairs.
4fill in blank
hardFill both blanks to create a zipped list of tuples from two arrays and print them.
C Sharp (C#)
string[] fruits = {"apple", "banana", "cherry"};
int[] counts = {5, 3, 7};
var zipped = fruits.[1](counts, ([2] f, c) => (f, c));
foreach (var (f, c) in zipped)
{
Console.WriteLine($"{f} has {c} items");
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select instead of Zip will not combine sequences.
Using 'var' instead of 'string' in tuple element type causes errors.
✗ Incorrect
Use Zip to combine sequences and specify tuple element types explicitly with 'string'.
5fill in blank
hardFill all three blanks to zip two arrays, filter pairs where sum is greater than 5, and create a list of sums.
C Sharp (C#)
int[] a = {1, 3, 5};
int[] b = {2, 4, 6};
var sums = a.[1](b, (x, y) => x + y)
.Where(sum => sum [2] 5)
.ToList();
Console.WriteLine(sums.[3]()); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select instead of Zip for pairing.
Using '<' instead of '>' in the filter condition.
Using Count() instead of Sum() to get total.
✗ Incorrect
Zip pairs elements, Where filters sums greater than 5, and Sum calculates total.