C# Property
C# Property
C# -
property
Prepared by
Hassan Jasim Muhammad
:Supervised By
Manal Ali
Year of Education
2022 – 2021
Contents
Introduction.............................................................................................................3
what is a property in c#............................................................................................3
Why We use properties...........................................................................................4
Example....................................................................................................................5
Conclusion................................................................................................................6
Refrences................................................................................................................. 7
2|Page
Introduction
what is a property in c#
A property is a member that provides a flexible mechanism to read,
write, or compute the value of a private field. Properties can be used as
if they are public data members, but they are actually special methods
called accessors.
Another Property in C# is a member of a class that provides a flexible
mechanism for classes to expose private fields. Internally, C# properties
are special methods called accessors. A C# property have two
accessors, get property accessor and set property accessor. A get
accessor returns a property value, and a set accessor assigns a new
value. The value keyword represents the value of a property.
3|Page
Why We use properties
Marking the class field public & exposing is a risky, as you will not have
control what gets assigned & returned.
To understand this clearly with an example lets take a student class
who have ID, pass mark , name.Now in this example some problem
with public field
4|Page
Example 1
Example 2
5|Page
Conclusion
6|Page
Refrences
https://www.w3schools.com/cs/cs_properties.php
http://etutorials.org/Programming/visual-c-sharp
http://etutorials.org/Programming/visual-c-sharp/
Part+III+Programming+Windows+Forms/
Chapter+11+An+Introduction+to+Windows+Forms/Conclusion/
7|Page