Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Format a Type with ToString () (http://www.go4expert.com/forums/format-type-tostring-t21334/)

arunlalds 13Mar2010 14:58

Format a Type with ToString ()
 
By default, ToString() will display the type’s name. To show your own
values, you must override the method with one of your own. To illustrate this, let’s
continue our Vertex3d class
Assume the class initially looks like this:
Code:

struct Vertex3d
{
private double _x;
private double _y;
private double _z;
public double X
{
get { return _x; }
set { _x = value; }
}
public double Y
{
get { return _y; }
set { _y = value; }
}
public double Z
{
get { return _z; }
set { _z = value; }
}
public Vertex3d(double x, double y, double z)
{
this._x = x;
this._y = y;
this._z = z;
}
}



All times are GMT +5.5. The time now is 21:42.