The difference between the fully qualified interface name and the property that it explicitly implemented

Explicitly implemented interface properties usually begin with the full name of the interface. However, if it is a nested interface, the property name will be a little inconsistent.

namespace NS
{
    public class Container
    {
        //FullName is NS.Container+ITest
        public interface ITest
        {
            int Prop { get; }
        }
    }

    public class Sample : Container.ITest
    {
        //Property name is NS.Container.ITest.Prop
        int Container.ITest.Prop { get; }
    }
}

Why is the property name not NS.Container+ITest.Prop? Or the interface is better called NS.Container.ITest. It would be more correct, wouldn't it?

+3
source share
2 answers

The type names that the CLR generates simply do not comply with the C # language naming conventions. A canonical example List<int>, a CLR type name will resemble List'1(backquote). Which is not a valid type identifier in C #, just as NS.Container + ITest is also invalid.

You need to use C # naming conventions in C # code.

+2

, NS.Container+ITest , ITest NS.Container, NS.Container+ITest.Prop . Prop Sample ( ), NS.Container.ITest.Prop. , , , .

0

All Articles