Recall & Review
beginner
What is a field in C#?
A field is a variable declared directly in a class or struct to store data. It holds the actual data for an object.Click to reveal answer
beginner
What is a property in C#?
A property is a member that provides controlled access to a field, usually with get and set accessors to read or write the value.
Click to reveal answer
intermediate
Why use properties instead of fields?
Properties allow validation, encapsulation, and control over how data is accessed or changed, unlike fields which are accessed directly.
Click to reveal answer
beginner
Show a simple example of a property with a private field in C#.
private int age; public int Age { get { return age; } set { if (value >= 0) age = value; } }
Click to reveal answer
intermediate
What is an auto-implemented property?
An auto-implemented property lets you declare a property without explicitly defining a backing field; the compiler creates it automatically.
Click to reveal answer
Which of the following is true about fields in C#?
✗ Incorrect
Fields are variables inside classes or structs that hold data directly, often marked private to protect data.
What does a property in C# typically include?
✗ Incorrect
Properties usually have get and set accessors to read and write values with control.
Why might you prefer a property over a public field?
✗ Incorrect
Properties let you add checks or other logic when values are read or changed, improving safety.
What is an auto-implemented property?
✗ Incorrect
Auto-implemented properties let you write less code by not declaring the backing field explicitly.
Which keyword is used to define a property in C#?
✗ Incorrect
Properties use get and set keywords to define accessors.
Explain the difference between a field and a property in C#.
Think about how you store data and how you control reading or writing it.
You got /4 concepts.
Describe why properties are preferred over public fields in object-oriented programming.
Consider how you keep data safe and flexible.
You got /4 concepts.