ToString() Method Overriding in C# with Example

ToString() Method Overriding in C# with Example
Rating: 5 - 3 Votes

ToString() Method Overriding in C# with Example

C#In dotnet, every type directly or directly inherit from Object class.  Object class contains some methods like ToString(), GetHashCode(), Equals(), etc and all of these methods are available to all the derived classes.  As the name suggests, ToString() works fine with the built in types but in case of complex types, it does not work as expected.  To fix this issue, we need to override this method so that we can get the desired output.  Example of ToString() override is given below.