Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a fluent method that returns the same object.
C Sharp (C#)
public class Builder { public Builder SetName(string name) { // set name logic return [1]; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the parameter 'name' instead of the object.
Returning null which breaks the chain.
✗ Incorrect
The fluent interface returns 'this' to allow chaining calls on the same object.
2fill in blank
mediumComplete the extension method to add a fluent method to the Builder class.
C Sharp (C#)
public static class BuilderExtensions { public static Builder [1](this Builder builder, int age) { // set age logic return builder; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method name that does not clearly indicate its purpose.
Omitting the 'this' keyword in the parameter.
✗ Incorrect
Extension methods typically use descriptive names like 'SetAge' to indicate setting a property.
3fill in blank
hardFix the error in the extension method to correctly return the builder for chaining.
C Sharp (C#)
public static Builder SetHeight(this Builder builder, double height) {
builder.Height = height;
return [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the property value instead of the builder.
Returning 'this' inside a static method which is invalid.
✗ Incorrect
The method must return the 'builder' object to continue the fluent chain.
4fill in blank
hardFill both blanks to create a fluent extension method that sets a string property and returns the builder.
C Sharp (C#)
public static Builder [1](this Builder builder, string city) { builder.[2] = city; return builder; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the property name as the method name.
Setting a property that does not exist.
✗ Incorrect
The method name 'SetCity' matches the fluent style, and the property 'CityName' is set inside the method.
5fill in blank
hardFill all three blanks to create a fluent extension method that sets an integer property with validation and returns the builder.
C Sharp (C#)
public static Builder [1](this Builder builder, int score) { if (score [2] 0) { builder.[3] = score; } return builder; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Setting a property with a different name.
✗ Incorrect
The method 'SetScore' sets the 'Score' property only if the score is greater than 0, then returns the builder.