+ 3
C#
Hello! Please help me how the value keyword works in properties, in the set accessor method. I don't understand what it does. I read many articles, many pages in books, I did not understand this. Explain, please.
3 Answers
+ 2
Value holds the value you want to assign to the property.
You can assign the value to the property or validate it first and check whether it fit in a certain range.
https://code.sololearn.com/cA4d4k7JqsS1/?ref=app
+ 1
What's the point of adding a keyword when you can use a regular variable? And and why it is possible to use value before it was initialized
if (value == 10)
{
........
}
age = value
0
Do you mean regular variable, field or property ?
regular variable = usefull within a class
field = can be set outside of a class, to give the class input
property = can be set outside of a class, and can validate input before setting the value to the inner object.
value is not uninitialized because it holds the value that you want to set to the property.