locked
Why should every class be derived from System.Object RRS feed

  • Question

  • Hi,

    CLR requires that every class be derived from System.Object. 

    What is the design objective behind this restriction.

    C++ does not have any such restriction , it is only in Java and C# that such a restriction exists. 

    What services does CLR provide through System.Object ?

    Thanks

    Vivekanand

     

     

     

     

    Wednesday, May 5, 2010 8:34 AM

Answers

  • Welcome to the MSDN Forums:

    According to it's documentation at http://msdn.microsoft.com/en-us/library/system.object(VS.80).aspx (Object Class (System)) :

    "Because all classes in the .NET Framework are derived from Object, every method defined in the Object class is available in all objects in the system. Derived classes can and do override some of these methods, including:

    Equals - Supports comparisons between objects.

    Finalize - Performs cleanup operations before an object is automatically reclaimed.

    GetHashCode - Generates a number corresponding to the value of the object to support the use of a hash table.

    ToString - Manufactures a human-readable text string that describes an instance of the class."

    Regards,

    Yasser.


    Don't be stickler and wine with William Shakespeare after the solution :^)
    "And this our life, exempt from public haunt, finds tongues in trees, books in the running brooks, sermons in stones, and good in everything." William Shakespeare
    • Marked as answer by SamAgain Thursday, May 13, 2010 12:58 AM
    Wednesday, May 5, 2010 8:55 AM
  • To support basic operations like comparison, tostring, boxing(specific type to object type) & unboxing(object type to specific type) etc. Also this makes sure that all classes in .net exposes standard set of opertations, properties.

     


    Jagatheesan
    • Marked as answer by SamAgain Thursday, May 13, 2010 12:58 AM
    Wednesday, May 5, 2010 8:59 AM

All replies

  • Welcome to the MSDN Forums:

    According to it's documentation at http://msdn.microsoft.com/en-us/library/system.object(VS.80).aspx (Object Class (System)) :

    "Because all classes in the .NET Framework are derived from Object, every method defined in the Object class is available in all objects in the system. Derived classes can and do override some of these methods, including:

    Equals - Supports comparisons between objects.

    Finalize - Performs cleanup operations before an object is automatically reclaimed.

    GetHashCode - Generates a number corresponding to the value of the object to support the use of a hash table.

    ToString - Manufactures a human-readable text string that describes an instance of the class."

    Regards,

    Yasser.


    Don't be stickler and wine with William Shakespeare after the solution :^)
    "And this our life, exempt from public haunt, finds tongues in trees, books in the running brooks, sermons in stones, and good in everything." William Shakespeare
    • Marked as answer by SamAgain Thursday, May 13, 2010 12:58 AM
    Wednesday, May 5, 2010 8:55 AM
  • To support basic operations like comparison, tostring, boxing(specific type to object type) & unboxing(object type to specific type) etc. Also this makes sure that all classes in .net exposes standard set of opertations, properties.

     


    Jagatheesan
    • Marked as answer by SamAgain Thursday, May 13, 2010 12:58 AM
    Wednesday, May 5, 2010 8:59 AM