Bird
0
0

You want a computed property that returns the full name by combining FirstName and LastName with a space. Which code correctly implements this?

hard🚀 Application Q8 of 15
C Sharp (C#) - Properties and Encapsulation
You want a computed property that returns the full name by combining FirstName and LastName with a space. Which code correctly implements this?
Apublic string FullName { get; set; } = FirstName + " " + LastName;
Bpublic string FullName { set => FirstName + " " + LastName; }
Cpublic string FullName() => FirstName + " " + LastName;
Dpublic string FullName => FirstName + " " + LastName;
Step-by-Step Solution
Solution:
  1. Step 1: Understand computed property for concatenation

    Computed property returns combined string dynamically using expression-bodied syntax.
  2. Step 2: Evaluate options

    public string FullName => FirstName + " " + LastName; correctly uses expression-bodied property. public string FullName { get; set; } = FirstName + " " + LastName; uses auto-property with initializer, which won't update if names change. public string FullName() => FirstName + " " + LastName; is a method, not a property. public string FullName { set => FirstName + " " + LastName; } uses set accessor incorrectly.
  3. Final Answer:

    public string FullName => FirstName + " " + LastName; -> Option D
  4. Quick Check:

    Computed property concatenates strings with => [OK]
Quick Trick: Use => to combine strings in computed properties [OK]
Common Mistakes:
MISTAKES
  • Using auto-properties with initializers
  • Confusing methods with properties
  • Using set accessor wrongly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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