Practice · 1 of 3
An Iterator From Scratch
CHALLENGE
Difficulty: intermediate+25 XP
Implement EvensUpTo(int n): yields every even number from 0 to n inclusive, using yield return. n < 0 yields nothing. Also implement TakeEvens: returns the first count evens of a sequence (fewer if the source runs out).
``csharp
static IEnumerable<int> EvensUpTo(int n);
static IEnumerable<int> TakeEvens(IEnumerable<int> source, int count);
``
Press Submit to check your solution.
Back to lesson: Practice: Iterators & Pipelines Practice