Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is object keyword in c sharp?
Posted
Updated 14-Aug-11 3:06am
v2

From MSDN (http://msdn.microsoft.com/en-us/library/9kkx3h3c.aspx[^]):

The object type is an alias for Object in the .NET Framework. In the unified type system of C#, all types, predefined and user-defined, reference types and value types, inherit directly or indirectly from Object. You can assign values of any type to variables of type object. When a variable of a value type is converted to object, it is said to be boxed. When a variable of type object is converted to a value type, it is said to be unboxed. For more information, see Boxing and Unboxing.

And the definition of Object:
Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Aug-11 0:06am    
Comprehensive, my 5.
--SA
Wendelius 15-Aug-11 1:04am    
Thank you :)
I think this an interesting way to make vivid what object/Object in .NET is: in VisualStudio in .NET: put something like this in code somewhere, set a breakpoint, then compile and run, and examine the values:
bool intValue = 32 is object;
bool stringValue = "hello" is object;
And notice that Intellisense will give you a pre-compile message pop-up over the right side of the equal operator that this expression is always true.

Ask yourself: what must be true if every .NET Type is-a object ?

Whoops: did I say 'every:' then ask yourself what it means that
bool nullValue = null is object; // => false
So, 'null' is not an object !

You want to get fancy: what about nullable types ? What do you think happens:
int? myNullInt = null; // compare with setting myNullInt = 32;

bool nullableType = myNullInt is object;
If you wanted to get philosophical, perhaps you might paraphrase Pascal, and say: "object/Object in .NET is that Type whose center is everywhere, and whose circumference is nowhere." With "nowhere" equal to null :)
 
Share this answer
 
Comments
Dalek Dave 15-Aug-11 3:53am    
Nice answer, Bill.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900