Tech Off Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Classes that don't inherit from System.Object?

Back to Forum: Tech Off
  • User profile image
    W3bbo

    'lo

    Is it possible to devise a class that doesn't inherit from System.Object?

    I ask this because my IntelliSense lists for my own classes are chock-full of members that aren't really applicable, like "ToString", "Equals", and "GetHashCode".

  • User profile image
    Maurits

    Nope.  Even value types and structs are objects.  void may be the sole exception (?) but that wouldn't exactly help.

  • User profile image
    Sven Groot

    Maurits wrote:
    void may be the sole exception (?)

    Void is not actually a type. There is a System.Void structure but that's really only used in reflection, and incidentally it does inherit from Object. Smiley

    EDIT: Also, even if you could make something that didn't inherit from Object it'd be a horribly bad idea. After all, anything that takes an object would be unable to take such a type. Collection classes (non-generic ones at least), the String.Format type stuff, all would be unable to use that type. The fact that everything is an object in the .Net CTS is what makes it so powerful and flexible.

  • User profile image
    blowdart

    W3bbo wrote:
    'lo

    Is it possible to devise a class that doesn't inherit from System.Object?

    I ask this because my IntelliSense lists for my own classes are chock-full of members that aren't really applicable, like "ToString", "Equals", and "GetHashCode".


    So write in filler methods and decorate them with

    [EditorBrowsable(EditorBrowsableState.Never)]

  • User profile image
    Maurits

    Pointer types explicitly do not inherit from object, though you can cast them to various numeric types (which do.)  But that's not likely to be useful either Sad

  • User profile image
    W3bbo

    Maurits wrote:
    Pointer types explicitly do not inherit from object, though you can cast them to various numeric types (which do.)  But that's not likely to be useful either Sad


    Blowdart's solved it Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.