1

When looking at mscorlib.dll via Object Browser in Visual Studio 2008, the IDE indicates that Int64 (as well as the other data types) has a base type of ValueType.

In C#, I am aware that structs (which Int64 is) do not support object inheritance. I even checked the type metadata of an assembly in which I declared a System.Int64 property of a class, and there was no indication of Int64 extending any classes. Structs can extend interfaces, and I am aware of this.

I am confused on why the struct Int64 is showing a BaseType of ValueType.

Could someone please explain?

dalt text

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
contactmatt
  • 18,116
  • 40
  • 128
  • 186

1 Answers1

3

All value types implicitly inherit System.ValueType.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I thought structs couldn't inherit from anything other than System.Object? ( http://msdn.microsoft.com/en-us/library/ah19swz4(VS.71).aspx ) – contactmatt Nov 22 '10 at 01:38
  • @contactmatt: Take a look at the accepted answer here: http://stackoverflow.com/questions/1682231/how-do-valuetypes-derive-from-object-referencetype-and-still-be-valuetypes/1682604#1682604 – LukeH Nov 22 '10 at 01:40
  • @LukeH - So the above MSDN documentation is wrong? As taken from the above MSDN link: "There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object." – contactmatt Nov 22 '10 at 01:46
  • 1
    @contactmatt: See the newer documentation: http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx `All value types are derived implicitly from the System.ValueType.` – SLaks Nov 22 '10 at 01:47
  • @contactmatt: The distinction is enforced automatically by the compiler. MSDN is more than likely telling you that you cannot specify that a struct inherit from any arbitrary class. – Cody Gray - on strike Nov 22 '10 at 01:48
  • @Cody Gray - Alright, so the .NET compiler forces the type inheritance, but I cannot (as I tested by the compiler) tell the struct to inherit anything but an interface. I think I got it. – contactmatt Nov 22 '10 at 02:08