Inherit from System.Object

It is well known that a C # class can inherit from only one base class. How does this make sense because all classes come from System.Object?

Also, if I look at the definition of the ValueType class (for example), which I know that inherits directly from System.Object, I see that this is just an abstract class. I expect to see: public abstract class ValueType: System.Object

+5
source share
9 answers

Inheritance is most easily visualized as a hierarchy or tree. See if that makes sense:

                     System.Object
                     /           \
                    /             \
                   /               \
MyProject.SomeClass                 MyProject.SomeBaseClass
                                         /           \
                                        /             \
                                       /               \
                   MyProject.SomeDerivedClass     MyProject.SomeOtherDerivedClass

MyProject.SomeDerivedClass, , , , MyProject.SomeBaseClass. MyProject.SomeBaseClass , System.Object.

MyProject.SomeDerivedClass System.Object, ; , , . , MyProject.SomeDerivedClass MyProject.SomeBaseClass, System.Object, .

+5

, # .

, . # .

inherits-members-from-type direct- .

, , System.Object, . System.Object , , .

.

, , . " " .

+21

;

Object <= Foo <= Bar <= Blap

, ( , , ).

+12

, System.Object

,

public myConreteClass : myBaseClass
{}

public myBaseClass : System.Object
{}

, , - System.Object

+2

A B, System.Object.

+1

:

.NET Framework; .

.

, , ( ) Cat Mammal, Animal, System.Object.

+1

,

public class Foo {}

, :

public class Foo : object {}

Bar Foo:

public class Bar : Foo {}

, Foo , Bar.

+1

# , , , calss .

+1

:

, Object

public class Object { } 

String,

public class String : Object { } 

StringWithColors, String

public class StringWithColors : String { } 

StringWithColors String Object.. ...

+1
source

All Articles