int a = 2;
Console.WriteLine(a.ToString()); // displays 2
// definition of ToString() here - public override string ToString();
Now, here are some of my understandings:
- All the classes in .net get a
ToString()
method, which is inherited from theObject
class. - A structure cannot be derived from a Class or another struct.
int
is a structure of typeInt32
, which gets a couple ofToString()
[With Parameters] methods from the Interfaces which it implements. - There is also a
ToString()
[without params] function in structInt32
According to http://msdn.microsoft.com/en-us/library/system.int32.tostring.aspx,
struct Int32 overrides ValueType.ToString() method
If a struct cannot inherit some class or struct, can you please explain how this ToString()
method is available for Int32
?