Complete the code to define a property with a get accessor that returns the value of the field.
private int _age;
public int Age {
get { return [1]; }
}The get accessor returns the value of the private field _age.
Complete the code to define a set accessor that assigns the input value to the field.
private string _name;
public string Name {
set { [1] = value; }
}The set accessor assigns the input value to the private field _name.
Fix the error in the set accessor to correctly assign the value to the field without recursion.
private double _price;
public double Price {
set { [1] = value; }
get { return _price; }
}Assigning to _price avoids recursive calls to the property Price.
Fill both blanks to create a property that only allows setting the field if the value is positive.
private int _quantity;
public int Quantity {
get { return _quantity; }
set {
if ([1] > 0) {
[2] = value;
}
}
}The set accessor checks if the input value is positive and assigns it to the field _quantity.
Fill all three blanks to create a property that converts the stored name to uppercase when getting and trims whitespace when setting.
private string _fullName;
public string FullName {
get { return [1].ToUpper(); }
set { [2] = value.[3](); }
}ToLower() instead of Trim() in set.The get accessor returns the uppercase version of the field _fullName. The set accessor trims whitespace from the input before assigning it to _fullName.