Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would .NET be able to function just as well without the use of type Object?

I am asking this because it seems like using Object seems to be an easy way out to solve certain problems, like "I don't have a specific type, so use Object", etc.

Also the reason this made me curious is because a colleague of mine told me that if .NET was a true object-oriented platform then it wouldn't have to have a catch all type like Object.

So if .NET didn't have the Object type, what would be the alternative ways to solve the occuring problems to make it function just the same?

Also just to note, this is not to bash .NET, as I use it daily in my work. Just want to know more about it.

EDIT: Another note I remembered is because the type Object exists, its effect ripples throughout the whole .NET. Like IEnumerable exists but also IEnumerable<T>. And in many situations you have to implement both the generic and non-generic version of things, etc.

like image 718
Joan Venge Avatar asked Sep 08 '10 18:09

Joan Venge


People also ask

What is .NET type?

NET type is a collection of members, which may be fields (i.e., they hold data of some type), methods (i.e., they contain code), or nested type definitions, and all members have some level of protection (e.g., public, private, protected).

What do all types in .NET derive from?

Because all classes in . NET are derived from Object, every method defined in the Object class is available in all objects in the system. Derived classes can and do override some of these methods, including: Equals - Supports comparisons between objects.

What is object in C sharp?

Object, in C#, is an instance of a class that is created dynamically. Object is also a keyword that is an alias for the predefined type System. Object in the . NET framework. The unified type system of C# allows objects to be defined.


2 Answers

I would say that the problem that is solved by Object is not "I don't have a specific type, so use Object", but rather "I don't really care what type this is; all I need to know it that it is an Object"

like image 145
Fredrik Mörk Avatar answered Sep 23 '22 00:09

Fredrik Mörk


It is a convenience, not only for use as a 'generic' type but also for reflection, garbage collection etc.

Other languages (C++) can do without, but I would hesitate to say that makes those languages more OOP.

like image 32
Henk Holterman Avatar answered Sep 23 '22 00:09

Henk Holterman