Sponsored Ad

Thursday, October 22, 2009

value (C# Reference)

The value of context keyword is used in the access program set forth in the statements of common property. It is similar to an input parameter in a method. The references of the word value of the value that the client code is trying to assign to the property. In the following example, MyDerivedClass has a property called Name that uses the parameter value to assign a new string for the field name support. From the standpoint of client code, the operation is written as a simple task.

class MyBaseClass
{
    // virtual auto-implemented property. Overrides can only
    // provide specialized behavior if they implement get and set accessors.
    public virtual string Name { get; set; }

    // ordinary virtual property with backing field
    private int num;
    public virtual int Number
    {
        get { return num; }
        set { num = value; }
    }
}

class MyDerivedClass : MyBaseClass
{
    private string name;

   // Override auto-implemented property with ordinary property
   // to provide specialized accessor behavior.
    public override string Name
    {
        get
        {
            return name;
        }
        set
        {
            if (value != String.Empty)
            {
                name = value;
            }
            else
            {
                name = "Unknown";
            }
        }
    }

}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers