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

Zip operation in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Zip Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Zip operation?
Consider the following C# code using Zip to combine two arrays. What will be printed?
C Sharp (C#)
var numbers = new[] {1, 2, 3};
var words = new[] {"one", "two", "three"};
var zipped = numbers.Zip(words, (n, w) => $"{n}-{w}");
foreach (var item in zipped) {
    Console.WriteLine(item);
}
Aone-1\ntwo-2\nthree-3
B1\n2\n3\none\ntwo\nthree
CCompilation error
D1-one\n2-two\n3-three
Attempts:
2 left
💡 Hint
Zip pairs elements from two sequences in order.
Predict Output
intermediate
2:00remaining
What is the output when sequences have different lengths?
What will this C# code print when using Zip on arrays of different lengths?
C Sharp (C#)
var a = new[] {10, 20, 30, 40};
var b = new[] {"a", "b"};
var zipped = a.Zip(b, (x, y) => $"{x}{y}");
foreach (var s in zipped) Console.WriteLine(s);
ARuntime exception
B10a\n20b
C10a\n20b\n30b\n40b
D10a\n20b\n30\n40
Attempts:
2 left
💡 Hint
Zip stops at the shortest sequence length.
🔧 Debug
advanced
2:00remaining
What error does this Zip code cause?
What error will this C# code produce when run?
C Sharp (C#)
var list1 = new List<int> {1, 2, 3};
List<string> list2 = null;
var zipped = list1.Zip(list2, (x, y) => x + y.Length);
foreach (var item in zipped) Console.WriteLine(item);
ANullReferenceException
BArgumentNullException
CNo error, prints 3 lines
DCompilation error
Attempts:
2 left
💡 Hint
Check what happens if one sequence is null.
Predict Output
advanced
2:00remaining
What is the output of this Zip with index?
What will this C# code print?
C Sharp (C#)
var nums = new[] {5, 10, 15};
var words = new[] {"five", "ten", "fifteen"};
var zipped = nums.Zip(words, (n, w) => $"{w}:{n}");
var indexed = zipped.Select((s, i) => $"{i}-{s}");
foreach (var item in indexed) Console.WriteLine(item);
A0-five:5\n1-ten:10\n2-fifteen:15
BCompilation error
C5-five\n10-ten\n15-fifteen
Dfive:5\nten:10\nfifteen:15
Attempts:
2 left
💡 Hint
Select with index adds the position before each string.
🧠 Conceptual
expert
2:00remaining
How many items are in the result of this Zip?
Given these sequences, how many items will the Zip produce?
C Sharp (C#)
var seq1 = Enumerable.Range(1, 100);
var seq2 = Enumerable.Range(1, 50);
var result = seq1.Zip(seq2, (x, y) => x + y);
A150
B100
C50
D0
Attempts:
2 left
💡 Hint
Zip stops at the shortest sequence length.