view raw
m.edmondson m.edmondson - 8 months ago 46
C# Question

Since Int32 is a value type why does it inherit .ToString()?

These are the docs about

that has prompted this question. They state:

Because Object is the base class of all reference types in the .NET
Framework, this behavior [.ToString()] is inherited by reference types that do not
override the ToString method.

Yet further on it goes to state:

For example, the base types such as Char, Int32, and String provide ToString implementations

However Int32 is a struct and hence must be a value type.

So what's going on here? Does Int32 implement it's very own .ToString() which has nothing to do with Object?


Int32 is a struct and therefore a value type. But:


Int32 derives from System.ValueType and this itself derives from System.Object. Et voilĂ ...