Skip to main content

Practice ยท 3 of 3

Debug: The Variance Crash

CHALLENGE
Difficulty: intermediate+25 XP

CopyAll was written for List<object> but callers hold IEnumerable<string> โ€” and the current version does not compile OR (after someone "fixed" it with a cast) crashes. Fix CopyAll so it accepts ANY sequence of references-to-string-or-base and returns a fresh List<string> of the same elements. ``csharp static List<string> CopyAll(IEnumerable<string> source); // and a generic overload usable for ANY element type: static List<T> CopyAll<T>(IEnumerable<T> source); ``

Back to lesson: Practice: Generic Design Practice