Difficulty: Easy
Correct Answer: class Employee : IPerson\n{\n private string str;\n public string FirstName\n {\n get { return str; }\n set { str = value; }\n }\n}
Explanation:
Introduction / Context:
The problem asks you to identify correct C# syntax for implementing a simple interface property. It also tests awareness of explicit vs. implicit interface implementation and the correct inheritance syntax.
Given Data / Assumptions:
Concept / Approach:
To implement an interface implicitly, the class must list the interface after its name using a colon and then provide a public member with the same signature. Explicit interface implementation would use the qualified name IPerson.FirstName, but the class must still declare that it implements IPerson.
Step-by-Step Solution:
Verification / Alternative check:
Compile Option A — succeeds. Compile B/C — fail with syntax/interface errors.
Why Other Options Are Wrong:
B lacks : IPerson and misuses explicit implementation syntax; C is not C# syntax.
Common Pitfalls:
Confusing VB “Implements” with C#’s colon syntax, and forgetting that explicit property implementations need the interface qualification and no access modifiers.
Final Answer:
class Employee : IPerson { ... public string FirstName { get; set; } }
Discussion & Comments