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

Stream vs async stream behavior in C Sharp (C#) - Interactive Practice

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

Complete the code to read all bytes from a stream synchronously.

C Sharp (C#)
using var stream = new MemoryStream(data);
byte[] buffer = new byte[stream.Length];
stream.[1](buffer, 0, buffer.Length);
Drag options to blanks, or click blank then click option'
AReadAsync
BRead
CWrite
DFlush
Attempts:
3 left
💡 Hint
Common Mistakes
Using ReadAsync instead of Read for synchronous reading.
Using Write which is for writing data, not reading.
2fill in blank
medium

Complete the code to asynchronously read bytes from a stream.

C Sharp (C#)
using var stream = new MemoryStream(data);
byte[] buffer = new byte[stream.Length];
await stream.[1](buffer, 0, buffer.Length);
Drag options to blanks, or click blank then click option'
AReadAsync
BRead
CWriteAsync
DFlushAsync
Attempts:
3 left
💡 Hint
Common Mistakes
Using Read instead of ReadAsync for asynchronous reading.
Using WriteAsync which is for writing data asynchronously.
3fill in blank
hard

Fix the error in the async stream reading loop.

C Sharp (C#)
await foreach (var chunk in stream.[1]())
{
    Process(chunk);
}
Drag options to blanks, or click blank then click option'
AReadChunksAsync
BReadAllBytesAsync
CReadAllAsync
DReadAsync
Attempts:
3 left
💡 Hint
Common Mistakes
Using ReadAsync which returns a Task, not an async stream.
Using method names that do not exist on Stream.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

C Sharp (C#)
var lengths = new Dictionary<string, int> { { [1], [2] } };
foreach (var word in words)
{
    if (word.Length > 3)
        lengths[word] = word.Length;
}
Drag options to blanks, or click blank then click option'
A"word"
Bword.Length
Cword
Dword.Length > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string literal "word" as key instead of the variable word.
Using a condition as a value instead of the length.
5fill in blank
hard

Fill all three blanks to create an async enumerable that yields uppercase words longer than 4 characters.

C Sharp (C#)
async IAsyncEnumerable<string> GetFilteredWords(IEnumerable<string> words)
{
    foreach (var [1] in words)
    {
        if ([2] > 4)
            yield return [3];
    }
}
Drag options to blanks, or click blank then click option'
Aword
Bword.Length
Cword.ToUpper()
Dwords
Attempts:
3 left
💡 Hint
Common Mistakes
Using the collection variable instead of the loop variable.
Yielding the original word instead of the uppercase version.