2013-02-21

C# Blooper №14: Weird / annoying interface method visibility rules.


Before reading any further, please read the disclaimer.

As it turns out, an explicit interface method implementation in C# must be tied to the base-most interface to which it belongs; it cannot be tied to a descendant interface.

namespace Test14
{
    class Test
    {
        interface A
        {
            void F();
        }

        interface B: A
        {
        }

        class C: B
        {
            void A.F() //OK
            {
            }

            void B.F() //error CS0539: 'B.F' in explicit interface declaration is not a member of interface
            {
            }
        }
    }
}

Well, sorry, but... it is.

-

2013-02-05

C# Blooper №13: Stack and Queue do not implement ICollection


Before reading any further, please read the disclaimer.

This is a blooper of the Common Language Runtime (CLR), not of the language itself: Stack<T> and Queue<T> derive from ICollection, but not from ICollection<T>, so they do not support the Remove( T ) method! Why, oh why?

-