Export (0) Print
Expand All
4 out of 11 rated this helpful - Rate this topic

get (C# Reference)

The get keyword defines an accessor method in a property or indexer that retrieves the value of the property or the indexer element. For more information, see Properties (C# Programming Guide), Auto-Implemented Properties (C# Programming Guide) and Indexers (C# Programming Guide).

This is an example of a get accessor in a property named Seconds:

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


    }

This is an example of a get accessor in an auto-implemented property:

class TimePeriod2
{
    public double Hours { get; set; }
}

For more information, see the C# Language Specification. The language specification is the definitive source for C# syntax and usage.

Reference

Concepts

Other Resources

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.