Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio .NET
Reference
Visual C# Language
C# Keywords
Types
Reference Types
 object

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
C# Programmer's Reference
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

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker