I want to override the Tostring() method for changing some characters. Is it possible? If yes, How can I do this?
In your class where you want to override it in, add:
public override string ToString()
{
// return your string representation
}
As per your question, to change some characters in the ToString
implementation, you need to call the existing ToString
method by using the base
keyword:
public override string ToString()
{
return base.ToString().Replace("something", "another thing");
}
Note that if you forget the base
keyword it will call itself repeatedly until you get a StackOverflowException
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With