about using property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    about using property

    Hello!

    Below is a definition of a struct called Second.

    Now to my question as you can see this struct has field called value.
    The struct has a property connected to this field called Value which is a
    getter.
    For example when I want to read this value field from within a member in the
    struct Second is the recommended way
    to read it by using the value field directly or by using the get property
    Value ?

    struct Second
    {
    private int value;

    public Second(int initialValue)
    { value = System.Math.Abs (initialValue) % 60; }


    public static implicit operator Second(int arg)
    { return new Second(arg); }

    public int Value
    { get { return value; } }

    public static bool operator==(Seco nd lhs, Second rhs)
    { return lhs.value == rhs.value; }


    public static bool operator !=(Second lhs, Second rhs)
    { return lhs.value != rhs.value; }

    public override bool Equals(object other)
    { return (other is Second) && Equals((Second) other); }

    public bool Equals(Second other)
    { return value == other.value; }

    public override int GetHashCode()
    { return value; }

    public static Second operator++(Seco nd arg)
    {
    arg.value++;
    if (arg.value == 60)
    {
    arg.value = 0;
    }
    return arg;
    }
    }

    //Tony


Working...