0
0
C Sharp (C#)programming~10 mins

Zip operation in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AZip
BSelect
CWhere
DOrderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select instead of Zip will not combine two sequences.
Where filters elements but does not combine sequences.
2fill in blank
medium

Complete 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'
AGroupBy
BZip
CSelect
DOrderBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select only projects one sequence, not combining two.
GroupBy groups elements but does not pair two sequences.
3fill in blank
hard

Fix 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'
AJoin
BSelect
CConcat
DZip
Attempts:
3 left
💡 Hint
Common Mistakes
Using Select only works on one sequence.
Concat joins sequences end to end, not element-wise.
4fill in blank
hard

Fill 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'
AZip
BSelect
Cstring
Dvar
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.
5fill in blank
hard

Fill 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'
AZip
B>
CSum
DSelect
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.