Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

object

The object type is an alias for System.Object in the .NET Framework. You can assign values of any type to variables of type object.

All data types, predefined and user-defined, inherit from the System.Object class. The object data type is the type to and from which objects are boxed.

Example

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 System.Object from the .NET Framework.

// keyword_object.cs
using System;
public class MyClass1 
{
   public int i = 10;
}

public class MyClass2 
{
   public static void Main() 
   {
      object a;
      a = 1;   // an example of boxing
      Console.WriteLine(a);
      Console.WriteLine(a.GetType());
      Console.WriteLine(a.ToString());
      Console.WriteLine();

      a = new MyClass1 ();
      MyClass1 ref_MyClass1;
      ref_MyClass1 = (MyClass1)a;
      Console.WriteLine(ref_MyClass1.i);
   }
}

Output

1
System.Int32
1

10

See Also

C# Keywords | Reference Types | Value Types

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft