Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC#yield return generatorsSingle-choice MCQ

Why does this method fail to throw the ArgumentNullException when first called, surprising the caller?

static IEnumerable<int> Take(int[] src, int n) { if (src == null) throw new ArgumentNullException(nameof(src)); for (int i = 0; i < n; i++) yield return src[i]; } // var q = Take(null, 3); // no exception here