Bird
0
0

Which of the following correctly defines a read-only property Score in C# that returns a private field _score?

easy📝 Syntax Q3 of 15
C Sharp (C#) - Properties and Encapsulation

Which of the following correctly defines a read-only property Score in C# that returns a private field _score?

Apublic int Score { set { _score = value; } }
Bpublic int Score { get { return _score; } }
Cpublic int Score { get; set; }
Dpublic int Score { get; private set; }
Step-by-Step Solution
Solution:
  1. Step 1: Identify read-only property syntax

    A read-only property has only a get accessor.
  2. Step 2: Check each option

    public int Score { get { return _score; } } returns the private field and has no set, making it read-only.
  3. Final Answer:

    public int Score { get { return _score; } } -> Option B
  4. Quick Check:

    Only get accessor means read-only [OK]
Quick Trick: Get accessor only means read-only property [OK]
Common Mistakes:
MISTAKES
  • Including a set accessor makes it writable
  • Using auto-properties with both get and set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes