Complete the code to declare a public field named 'age' of type int.
public class Person { public [1] age; }
The field 'age' should be declared with the type int to store integer values.
Complete the code to declare a public property named 'Age' with get and set accessors.
public class Person { public int [1] { get; set; } }
Properties usually start with a capital letter, so Age is the correct property name.
Fix the error in the property declaration by completing the code.
public class Person { private int _age; public int Age { get { return [1]; } set { _age = value; } } }
The getter should return the private field _age to provide the stored value.
Fill both blanks to create a property 'Name' with a private field '_name' and a setter that trims whitespace.
public class Person { private string [1]; public string Name { get { return [2]; } set { [2] = value.Trim(); } } }
The private field is '_name' and both getter and setter use it to store and return the trimmed name.
Fill all three blanks to create a read-only property 'IsAdult' that returns true if 'Age' is 18 or more.
public class Person { public int Age { get; set; } public bool [1] { get { return Age [2] [3]; } } }
The property 'IsAdult' returns true when 'Age' is greater than or equal to 18.