This blog defines the ToString() method in VB.NET.
ToString() method
The
ToString
method should provide the string representation of an object.
We can override
ToString() method for
Rectangle.
This function changes the result to string format. It is needed when you want to have your output as a string format, like when you want to pass is to a label text property, and your original output is for example , Date/Time format. or pass it to a database field with varchar datatype.
For example
C# code
using System;
class Rectangle
{
public int Width;
public int Height;
public string ToString()
{
return "Rectangle: " + Width + " by " + Height;
}
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle();

Join the conversation! Your thoughts help the community grow.