Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a copy of the record with a new Age.
C Sharp (C#)
var person2 = person [1] { Age = 30 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'with' to copy a record.
Trying to use 'copy' or 'clone' which are not valid keywords here.
✗ Incorrect
The 'with' expression creates a copy of the record with specified property changes.
2fill in blank
mediumComplete the code to define a record Person with properties Name and Age.
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 'name' which is not consistent with C# naming conventions.
Using 'FullName' which is not defined in the record.
✗ Incorrect
The property name should be 'Name' to match the usage in the code.
3fill in blank
hardFix the error in the code to create a new record with a changed Age.
C Sharp (C#)
var person2 = person [1] { Age = 35 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'copy' or 'clone' which are not valid C# keywords.
Using 'new' which creates a new instance but does not copy existing values.
✗ Incorrect
The 'with' keyword is required to create a copy with modified properties in records.
4fill in blank
hardFill both blanks to create a copy of the record with a new Name and Age.
C Sharp (C#)
var person3 = person [1] { Name = [2], Age = 40 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'with' for copying.
Not using quotes around the string value for Name.
✗ Incorrect
Use 'with' to copy the record and assign the new Name as "John".
5fill in blank
hardFill all three blanks to create a copy with uppercase Name and incremented Age.
C Sharp (C#)
var person4 = person [1] { Name = person.Name.[2](), Age = person.Age [3] 1 };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'with' for copying.
Using 'ToLower' instead of 'ToUpper' for the Name.
Using '-' instead of '+' to increment Age.
✗ Incorrect
Use 'with' to copy, 'ToUpper()' to uppercase the Name, and '+' to add 1 to Age.