+ 2

property in C# what can does to me in my app

9th Apr 2017, 5:01 PM
ALAMOUDI, WAEL MAKKI S
ALAMOUDI, WAEL MAKKI S - avatar
1 Answer
+ 2
Properties are pretty and a more elegant way to share data with the outside (of the object). They are methods inside. They enclose a getter and/or a setter, which are methods. This can be very useful for doing the workaround for value changing. Checking that the new value is legal and passes your restrictions, notifying someone who is interested in the change of that property, for example. Properties can be binded. I'm not prefessional in this topic, but in C# you can bind these properties to the UI layer, getting rid of many checks from the UI for data, for presenting the right values. Easy to read. When you see something like: public int Number { get; private set; } Then you see instantly, that Number is shared publicly, but can be set only from inside. Also, this was an auto-property without method bodies, which do create a variable with the given type and also its simple getter and setter with the given access modifiers. Fast and elegant work :)
17th Apr 2017, 8:27 AM
Magyar DĂĄvid
Magyar DĂĄvid - avatar