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

With expressions for immutable copies 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 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'
Anew
Bcopy
Cclone
Dwith
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.
2fill in blank
medium

Complete 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'
AName
Bname
CFullName
DAge
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.
3fill in blank
hard

Fix 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'
Acopy
Bwith
Cclone
Dnew
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.
4fill in blank
hard

Fill 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'
Awith
B"John"
C"Alice"
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'with' for copying.
Not using quotes around the string value for Name.
5fill in blank
hard

Fill 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'
Awith
BToUpper
C+
D-
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.