Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does every class in .NET inherit from Object?

Tags:

c#

object

I don't understand it...

Why do they need a common base?

like image 732
Tom Avatar asked Oct 17 '09 23:10

Tom


1 Answers

The question presupposes a falsehood. They don't need a common base type. This choice was not made out of necessity. It was made out of a desire to provide the best value for the customer.

When designing a type system, or anything else for that matter, sometimes you reach decision points -- you have to decide either X or not-X. Common base type or no common base type. When that happens you weigh up the costs and the benefits of X to determine the net value, and then you weigh up the costs and the benefits of not-X to determine the net value, and you go with the one that was higher value. The benefits of having a common base type outweigh the costs, and the net benefit thereby accrued is larger than the net benefit of having no common base type. So we choose to have a common base type.

That's a pretty vague answer. If you want a more specific answer, try asking a more specific question.

like image 157
Eric Lippert Avatar answered Dec 30 '22 05:12

Eric Lippert