Does the non-original version of IEnumerable support deferred execution?

If so, on which versions of the .NET Framework is supported?

I tested this on the .NET Framework 4.0 and it works great:

using System;
using System.Collections.Generic;

public class TestClass
{
    public IEnumerable Defer()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
+3
source share
3 answers

Yes, it has been supported since the keyword yieldwas. The only difference is that he is more or less IEnumerable<object>, which can lead to inefficiency if he has to do boxing. Other than that, it's exactly the same.

+4
source

Since keywords are yieldreduced to deceiving the compiler, perhaps this should work. This certainly works for version 2.0; However, I would conspire to make any statements about 1.1.

+1

Unoriginal IEnumerable does not implement IDisposable. It is possible that VB.Net and C # will be duck-type either IDisposable or the .Dispose () method when using an enumerator that does not support IEnumerable (Of T), but, of course, you cannot rely on all consumers not common IEnumerable to do this. If the consumer enumerated does not work properly. Specify () it, the execution of the enumerator, including explicit or implicit final sentences , will be canceled.

+1
source

Source: https://habr.com/ru/post/1784007/


All Articles