it seems this code is valid. I am wondering what if getTest(1)
IEnumerable<int> getTest(int n)
{
if (n == 0)
yield return 1;
else
;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It will return an empty but non-null
IEnumberable<int>.Once you’ve marked a method as an iterator (by using
yieldanywhere in the method), it can execute zero or moreyield returns to return data in the sequence.In fact, the simplest way to get an empty IEnumberable is
IEnumerable<T> Empty() { yield break; }.Or just call
Enumerable.Empty<T>().