From the course: Learning C#

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

String representation

String representation - C# Tutorial

From the course: Learning C#

String representation

- [Instructor] In C#, every class implicitly inherits from the base object class, which you can find in the documentation at this link. Because of this inheritance, every class, both built-in and the ones that you create inherit the ToString function from the object class. And if I scroll down to the ToString method, you can find that here in the documentation at this link. The purpose of the ToString function is, as you would imagine, to return a string representation of the object that is suitable for display. So when you create your own classes, it's a good idea to override this method and generate your own string representation of your class. The built-in types use this method to display their data as strings. So let's jump over to Visual Studio Code, and let's see how this works. So here in the StringRep folder, I'm going to open up the Program code, as well as the Book code. So let's go back to our Program code…

Contents