1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Format a Type with ToString ()

Discussion in 'C#' started by arunlalds, Mar 13, 2010.

  1. arunlalds

    arunlalds Banned

    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;
    }
    }
    
     

Share This Page