object (C# Reference)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

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.

The following sample shows how variables of type object can accept values of any data type and how variables of type object can use methods on Object from the .NET Framework.

class ObjectTest
   public int i = 10;

class MainClass2
   static void Main()
      object a;
      a = 1;   // an example of boxing

      a = new ObjectTest();
      ObjectTest classRef;
      classRef = (ObjectTest)a;
/* Output
 * 10

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

C# Reference
C# Programming Guide
C# Keywords
Reference Types
Value Types