Does an IEnumerable obtained from a yield expression can ever be null?
No. The C# compiler converts your iterator block into an iterator instance, which is what is returned from your method. This can never be null.
That said, it is of course possible to yield null values within your enumeration, provided that the generic type of your enumerable is a reference type or a nullable type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With