C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

19th Feb 2022, 3:43 PM
‎أندريه‎
‎أندريه‎ - avatar
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
19th Feb 2022, 4:17 PM
sneeze
sneeze - avatar
+ 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
19th Feb 2022, 5:12 PM
‎أندريه‎
‎أندريه‎ - avatar
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.
19th Feb 2022, 5:59 PM
sneeze
sneeze - avatar