0
0
C Sharp (C#)programming~10 mins

Computed properties in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a computed property that returns the full name.

C Sharp (C#)
public class Person {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string FullName => [1];
}
Drag options to blanks, or click blank then click option'
AFirstName + " " + LastName
BFirstName - LastName
CFirstName / LastName
DFirstName * LastName
Attempts:
3 left
💡 Hint
Common Mistakes
Using arithmetic operators like - or * instead of + for strings.
Forgetting to add a space between names.
2fill in blank
medium

Complete the code to create a computed property that returns the area of a rectangle.

C Sharp (C#)
public class Rectangle {
    public double Width { get; set; }
    public double Height { get; set; }
    public double Area => [1];
}
Drag options to blanks, or click blank then click option'
AWidth - Height
BWidth / Height
CWidth * Height
DWidth + Height
Attempts:
3 left
💡 Hint
Common Mistakes
Adding width and height instead of multiplying.
Using division or subtraction by mistake.
3fill in blank
hard

Fix the error in the computed property that returns the initials of a person.

C Sharp (C#)
public class Person {
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Initials => [1];
}
Drag options to blanks, or click blank then click option'
AFirstName[0].ToString() + " " + LastName[0].ToString()
BFirstName[0] + LastName[0]
CFirstName.Substring(0, 1) + LastName.Substring(0, 1)
DFirstName[0].ToString() + LastName[0].ToString()
Attempts:
3 left
💡 Hint
Common Mistakes
Adding chars directly without converting to string.
Forgetting to add a space between initials.
4fill in blank
hard

Fill both blanks to create a computed property that returns the perimeter of a rectangle.

C Sharp (C#)
public class Rectangle {
    public double Width { get; set; }
    public double Height { get; set; }
    public double Perimeter => 2 * ([1] + [2]);
}
Drag options to blanks, or click blank then click option'
AWidth
BHeight
CLength
DDepth
Attempts:
3 left
💡 Hint
Common Mistakes
Using properties that don't exist like Length or Depth.
Forgetting to add both width and height inside the parentheses.
5fill in blank
hard

Fill all three blanks to create a computed property that returns the volume of a box.

C Sharp (C#)
public class Box {
    public double Width { get; set; }
    public double Height { get; set; }
    public double Depth { get; set; }
    public double Volume => [1] * [2] * [3];
}
Drag options to blanks, or click blank then click option'
AWidth
BHeight
CDepth
DLength
Attempts:
3 left
💡 Hint
Common Mistakes
Using a property named Length which does not exist.
Missing one of the dimensions in the multiplication.