m.edmondson m.edmondson - 1 year ago 83
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?

Answer Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download