Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inherit from System.Object [duplicate]

Tags:

c#

It is well known that C# class can inherit only from a Single Base class How does it make sense because all classes derive from System.Object?

Also, If I look into class ValueType definition (for example), which i know that inherits directly from System.Object, i see that it is just an abstract class. i expect to see: public abstract class ValueType : System.Object

like image 692
user829174 Avatar asked Nov 28 '11 17:11

user829174


1 Answers

It is well known that C# class can inherit only from a single base class.

That is not well-known because that statement is absolutely false. In C# a class can inherit members from arbitrarily many base classes and interfaces.

You have confused the inherits-members-from-type relationship with the directly-derives-from-type relationship.

The actual rule is that every class except System.Object derives directly from exactly one class. System.Object is unique in that it is the only class that derives directly from nothing.

Every class and every interface can derive directly from arbitrarily many interfaces.

A class or interface inherits the members of every class or interface that it derives from, either directly or indirectly. The "direct or indirect derivation" relationship is the transitive closure of the direct derivation relationship.

like image 145
Eric Lippert Avatar answered Oct 03 '22 14:10

Eric Lippert