Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

set (C# Reference)

Defines an accessor method in a property or indexer that set the value of the property or the indexer element. See Properties and Indexers for more information.

This is an example of a set accessor for a property called Seconds:

class TimePeriod
{
    private double _seconds;
    public double Seconds
    {
        get { return _seconds;  }
        set { _seconds = value; }
    }
}

For more information, see the following sections in the C# Language Specification:

  • 1.6.6.2 Properties

  • 10.6.2 Accessors

Community Additions

ADD
Show:
© 2015 Microsoft