+ 1
How to use "set" accesor ?
for ex : class Dog { private string age; public string Age { get { return age; } set { age = value; } } } static void Main(string[] args) { Dog p = new Dog(); /*how to change the age using set accesor how to give a value to "value" ?? */ }
1 Resposta
+ 8
The set accessor will be invoked when we assign the property with a specific value.
For example the following statement:-
p.Age = 8;
Right-hand-side 8 will be treated as the value in this case.
In addition, the statement above will results compilation error if the setter was removed, which effectively turn the property into read-only and assignable via constructor.