Properties in C sharp Arabic I #25








 Properties in C sharp Arabic I #25

Suggested Videos

Method Overloading in C sharp Arabic #24


❑ The need for Properties.



Why Properties

❑ Marking the class fields public and exposing to the external world is bad, as you will not have control over what gets assigned and returned.

Problems with Public Fields
--------------------------------------------
1-ID should always be non negative number
2-Name cannot be set null . 
3-if student Name is missing “no name “should be returned.
4-PassMark should be read only.




❑ Programing languages that does not have properties use getter and setter methods to encapsulate and protect fields.

In this example we use the Setid(int id) and Getid() methods to encapsulate _id class filed. As a result, we have better control on what gets assigned and returned form the _id field. Note: Encapsulation is one of the primary pillars of object oriented programming.

Follow Us

YouTube

 If you want to download pptx : click Telegram

Facebook

Twitter

Instagram

Tik Tok

إرسال تعليق

أحدث أقدم