Question is simple and asked in the title.
C# 4.0 Specification says: (§4.2.2)
The object class type is the ultimate
base class of all other types. Every
type in C# directly or indirectly
derives from the object class type.
Interface types, not being classes,
are not derived from object.
Reality says:
Type t = typeof(ICloneable).BaseType;
Console.WriteLine(t == null);
True
So is spec wrong or what? Whom to believe?
It’s not quite as simple a question as you might think 🙂
Interfaces don’t derive from
objectbut you can call the members ofobjecton them. So you can callToString()on an expression which has a compile-time type ofIDisposable, for example.Coincidentally, I overhead a conversation between Neal Gafter and Eric at NDC discussing exactly this point…
I believe section 4.2.2 of the spec is over simplified, unfortunately. Hopefully Mads and Eric will fix it up for a future release – I’ll mail them to make sure they see this question.
I’m also struggling to find anything in the spec to back up the rest of this answer. Section 3.4.5 of the C# 4 spec comes as close as I can find:
The conversion from an interface type to
objectis covered by section 6.1.6: