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

Async streams with IAsyncEnumerable 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 declare an async stream method that returns integers.

C Sharp (C#)
public async [1]<int> GetNumbersAsync()
{
    yield return 1;
    await Task.Delay(100);
    yield return 2;
}
Drag options to blanks, or click blank then click option'
AList
BIAsyncEnumerable
CTask
DIEnumerable
Attempts:
3 left
💡 Hint
Common Mistakes
Using IEnumerable instead of IAsyncEnumerable
Returning Task instead of IAsyncEnumerable
2fill in blank
medium

Complete the code to asynchronously iterate over the async stream.

C Sharp (C#)
await foreach (var number [1] GetNumbersAsync())
{
    Console.WriteLine(number);
}
Drag options to blanks, or click blank then click option'
Afrom
Bof
Cin
Don
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'of' instead of 'in'
Using 'from' or 'on' which are invalid here
3fill in blank
hard

Fix the error in the async stream method signature.

C Sharp (C#)
public [1] async IAsyncEnumerable<int> GenerateAsync()
{
    yield return 1;
    await Task.Delay(100);
    yield return 2;
}
Drag options to blanks, or click blank then click option'
Astatic
Bvoid
Casync
DTask
Attempts:
3 left
💡 Hint
Common Mistakes
Placing async before static
Using void as return type for async streams
4fill in blank
hard

Fill both blanks to correctly yield values asynchronously with delay.

C Sharp (C#)
public async IAsyncEnumerable<int> CountAsync()
{
    for (int i = 0; i [1] 3; i++)
    {
        await Task.Delay(100);
        yield [2] i;
    }
}
Drag options to blanks, or click blank then click option'
A<
B>
Creturn
Dyield return
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in loop condition
Using 'return' instead of 'yield return'
5fill in blank
hard

Fill all three blanks to filter and yield only even numbers asynchronously.

C Sharp (C#)
public async IAsyncEnumerable<int> EvenNumbersAsync(int[] numbers)
{
    foreach (var num in numbers)
    {
        if (num [1] 2 [2] 0)
        {
            await Task.Delay(50);
            yield [3] num;
        }
    }
}
Drag options to blanks, or click blank then click option'
A%
B==
Cyield return
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for even check
Using 'return' instead of 'yield return'