Search code examples
c#.netanonymous-typesanonymous-classstringcomparer

Can an anonymous type inherit from another type?


According to the MSDN documentation on the StringComparer.OrdinalIgnoreCase property:

The OrdinalIgnoreCase property actually returns an instance of an anonymous class derived from the StringComparer class.

Is this a feature I'm unfamiliar with—anonymous types with inheritance? Or by "anonymous class" did the author simply mean "internal class deriving from StringComparer, not visible to client code"?


Solution

  • If you look at the source code for StringComparer, you can see that OrginalIgnoreCase returns an instance of OrdinalComparer, which is derived from StringComparer.

    There's nothing 'anonymous' about this that I can see, it's just that it's internal so you can't see it from outside the framework.