1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Format a Type with ToString ()

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

  1. arunlalds

    arunlalds Banned

    Joined:
    Mar 12, 2010
    Messages:
    43
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    student
    Location:
    India
    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