Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If so, on what .NET Framework versions is it supported?

I have tested this on .NET Framework 4.0 and it works fine:

using System;
using System.Collections.Generic;

public class TestClass
{
    public IEnumerable Defer()
    {
        yield return 1;
        yield return 2;
        yield return 3;
    }
}
like image 658
Edgar Gonzalez Avatar asked Dec 07 '25 09:12

Edgar Gonzalez


2 Answers

Yes, it is supported ever since the yield keyword was. The only difference is that it's more or less IEnumerable<object>, which might lead to inefficiencies if it has to do boxing. Other than that, it's exactly the same.

like image 78
Mike Caron Avatar answered Dec 10 '25 01:12

Mike Caron


As the yield keywords are reduced to compiler trickery, presumably this should work. It certainly works for the 2.0 runtime; I'd hesitate to make any statements about 1.1, however.

like image 30
Ben Avatar answered Dec 10 '25 03:12

Ben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!