Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Section A.12. Properties and indexers

A.12. Properties and indexers

Properties are function members that are run when a particular attribute is retrieved or assigned. They can be used for validating the value that’s being set or lazily creating an expensive attribute only when it’s needed. A property definition looks like this:

class Heist {
    //...
    private float executionTime;
    public float Hours {
        get {
            return this.executionTime / 3600;
        }
        set {
            this.executionTime = value * 3600;
        }
    }
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint