I have a get-only property in C # that returns IEnumerable . If this property will only ever be given once, then I could define my property as follows:
public IEnumerable Derp { get { yield return new SomeObject(); } }
But how can I do this with a C # 6 expression? The following approaches do NOT work:
// These definitions do NOT work public IEnumerable Derp => yield return new SomeObject(); public IEnumerable Derp => yield new SomeObject();
CS0103 compiler return error: "In the current context, the name" yield "does not exist. Is the yield ing element a physique expression even possible in C # 6? How about in C # 7?
I know that an IEnumerable member that returns only once looks smelly, but I'm mostly just curious. I came across this situation while experimenting with the NUnit TestCaseSource API, trying to provide a method that gives only one test case. I could also see that this applies to Unity developers who want to define an expression method that will be called using StartCoroutine ().
In any case, in advance for your thoughts!
source share