C# Object

In this chapter you will learn:

  1. What is C# Object
  2. Object methods

Description

object (System.Object) is the base class for all types. Any type can be upcast to object.

Syntax

The object class has the following members:


public class Object
{//from w  w w  .j av a 2s .  c o  m
  public Object();
  
  public extern Type GetType();
  
  public virtual bool Equals (object obj);
  public static bool Equals  (object objA, object objB);
  public static bool ReferenceEquals (object objA, object objB);
  
  public virtual int GetHashCode();
  
  public virtual string ToString();
  
  protected override void Finalize();
  protected extern object MemberwiseClone();
}

object(System.Object) is the super class for all types. We can always cast to object.


using System;//ww  w. j a  v  a2  s.c  o  m

class Rectangle{
   
}

class Program
{
    static void Main(string[] args)
    {

        object o = new Rectangle();
    }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. What is new operator
  2. How to use new operator
  3. Use new operator with value objects
  4. Object instance for class
Home »
  C# Tutorial »
    C# Types »
      C# Object
C# Object
C# new operator
C# this Reference
C# Null
C# Nullable Types
C# ToString Method
C# Object Initializers
C# GetHashCode
C# Object Casting and Reference Conversions