Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a record named Person with two properties.
C Sharp (C#)
public record Person(string [1], int Age); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase property names which is against C# naming conventions.
Using unrelated property names.
✗ Incorrect
The record property should be named Name to match common conventions.
2fill in blank
mediumComplete the code to create two Person records with the same values.
C Sharp (C#)
var person1 = new Person("Alice", 30); var person2 = new Person("Alice", [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different ages which makes the records unequal.
Confusing the age values.
✗ Incorrect
Both records must have the same age 30 to be equal by value.
3fill in blank
hardFix the error in the equality check between two Person records.
C Sharp (C#)
bool areEqual = person1 [1] person2; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using single = which is assignment, not comparison.
Using != which checks inequality.
Using 'equals' which is not valid syntax in C#.
✗ Incorrect
Use the == operator to check value equality between records.
4fill in blank
hardFill both blanks to override the ToString method in the Person record.
C Sharp (C#)
public override string ToString() => $"[1]: [2]";
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using combined strings instead of separate properties.
Using class name instead of property names.
✗ Incorrect
The ToString method should return the person's Name and Age values.
5fill in blank
hardFill all three blanks to create a new Person record with updated Age using the with-expression.
C Sharp (C#)
var olderPerson = person1 with { [1] = [2] + [3] };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to update the Name property instead of Age.
Using incorrect syntax for the with-expression.
✗ Incorrect
The with-expression updates the Age property by adding 1 to person1.Age.