3 ms·
Because a property is actually a method, so other, internal state could change what the property returns. Think of something like an "IsConnectionOpen" flag. Th
by moron4hire 12y ago
Because a property is actually a method, so other, internal state could change what the property returns. Think of something like an "IsConnectionOpen" flag. The class' internals may change it as if it is not readonly, but to the consuming code, the IsConnectionOpen property should appear readonly.
- andrea_s 12y agoThat's clear - but that's not the case presented in the slides... "Automatic" is clear, "getter-only" is clear, but "automatic getter-only" leaves me scratching my head.
- moron4hire 12y agoDo you know where it is in the video? Are they not talking about something like this? public bool IsOpen{get; private set;} public void Open(){ try{ // do some complex work this.IsOpen = true; } catch{ this.IsOpen = false; } } public void Close(){ // do some other work this.IsOpen = false; }
- andrea_s 12y agoNot sure about the minute, the video is prohibitively long... It's on the 9th slide: https://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fsessions%2fteched%2feu%2f2014%2fDEV-B345.pptx https://view.officeapps.live.com/op/view.aspx?src=http%3a%2f...
- moron4hire 12y agoI see. Maybe they mean "implicit private set"? Otherwise, one of the sibling comments has a good point about the binary compatibility issues with fields vs properties.