Is there any way to optionally return a null with a \"return yield\" driven iterator?
I would like to return a null in some cases and I don\'t think this is particul
There is no way to return a null IEnumerable
from within an iterator method. You can return null values in the iterator but not a null IEnumerable
What you could do though is have a wrapper method which either returns null or calls to the real iterator
static IEnumerable GetItems() {
if (false) {
return GetItemsCore();
}
return null;
}
static IEnumerable GetItemsCore() {
yield return "Andy";
yield return "Jennifer";
}