score:2

Accepted answer

that's because derivedenumerator implements both ienumerable<basethingy> and ienumerable<derivedthingy> (indirectly via ireadonlycolleciton). so when you do

var y = derivedenumerator.where(s => s.gethashcode() == s.gethashcode());

compiler cannot figure out what is the type of s in lamdba. is that derivedthingy? is that basethingy? both are possible. so you need to tell it explicitly what that is:

var y = derivedenumerator.where<derivedthingy>(s => s.gethashcode() == s.gethashcode());

or

var y = derivedenumerator.where((derivedthingy s) => s.gethashcode() == s.gethashcode());

that said, it's quite unusual design and you might reconsider it. how exactly depends on what you are trying to do (so, why do you need to inherit enumerators this way).

score:0

ambiguity issue

namespace classlibrary1
{
    public class basethingy { }

    public class derivedthingy : basethingy { }

    public class baseenumerator : ireadonlycollection<basethingy>
    {
        public int count => throw new notimplementedexception();

        public ienumerator<basethingy> getenumerator()
        {
            throw new notimplementedexception();
        }

        ienumerator ienumerable.getenumerator()
        {
            throw new notimplementedexception();
        }
    }

    public class derivedenumerator : baseenumerator, ireadonlycollection<derivedthingy>
    {
        ienumerator<derivedthingy> ienumerable<derivedthingy>.getenumerator()
        {
            throw new notimplementedexception();
        }
    }

    public class application
    {
        public void main()
        {
            baseenumerator baseenumerator = new baseenumerator();
            derivedenumerator derivedenumerator = new derivedenumerator();

            // works...
            var x = baseenumerator.where(s => s.gethashcode() == s.gethashcode());

            // works now
            var y = derivedenumerator.where<derivedthingy>(s => s.gethashcode() == s.gethashcode());
        }
    }
}

Related Query

More Query from same tag