Complete the code to make the property read-only.
public class Person { private string name; public string Name { get { return [1]; } } }
The get accessor returns the private field name, making the property read-only.
Complete the code to make the property write-only.
public class Account { private decimal balance; public decimal Balance { set { [1] = value; } } }
The set accessor assigns the incoming value to the private field balance, making the property write-only.
Fix the error in the read-only property to avoid infinite recursion.
public class Product { private int stock; public int Stock { get { return [1]; } } }
Returning the private field stock avoids infinite recursion caused by returning the property itself.
Fill both blanks to create a read-only property with a private setter.
public class Employee { public int Id { get; [1] } public string Name { get; [2] } }
Using private set allows the property to be set only inside the class, making it effectively read-only from outside.
Fill all three blanks to create a write-only property with a private getter.
public class Secret { private string data; public string Data { [1] { return data; } [2] { data = value; } } private string GetData() { return [3]; } }
The property has a private getter and a public setter, making it write-only from outside. The private method returns the private field data.