Preventing System.Object Inheritance RRS feed

  • Question

  • I know that the languages using .NET automatically inherit the System.Object for type uniformity but in some cases it seems unnecessary.  For example, if you're building a library that uses unmanaged classes and don't want the overhead.  I've been able to remove the inheritance via the MSIL and everything works fine but I just wanted to ask whether this will come back to haunt me (if so, why). 


    Tuesday, June 29, 2010 3:26 PM


  • I would strongly recommend against this.


    For starters, inheriting object doesn't really add overhead in the CLR - it's pretty much built into the runtime.


    That being said, supposing this actually has an effect (I don't believe removing the IL showing the inheritance actually changes anything), it would cause your objects to behave in a very non-standard, unexpected manner.


    If you're building a library of unmanaged classes, and you don't want to derive from System.Object, why not just make it an unmanaged library (just don't compile with /clr).  This will make the objects unusable from managed code, but also avoid the overhead of managed code.


    You could then just compile in any managed objects that should be managed with /clr.

    Reed Copsey, Jr. -
    • Marked as answer by SamAgain Tuesday, July 6, 2010 7:08 AM
    Tuesday, June 29, 2010 3:59 PM