jay's old blog

this blog will be deleted soon - please visit my new blog - https://thesanguinetechtrainer.com

String – Formatting – ToString

Another cool thing about string is that it has a default implementation of toString method. You have already seen this in action in many of our code samples. Just to refresh, if you were to use the tostring method with an int, you will get a string representation of that int value.  

Now, that is pretty cool. The same string method is available for every type (and hence all its objects) that you define. By default, it simply gives the type of the object. However, you are happy to override it, and make it give any string that you want. It is normal practice to give a string representation of your object. This is particularly useful when you are building json services or when you want other objects to get a string equivalent of the object in question.  

Of course, find the code that does this here.

Follow me on twitter, facebook and instagram for more updates. Thanks!

Comments are closed