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

Record declaration syntax 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 declare a simple record named Person.

C Sharp (C#)
public [1] Person;
Drag options to blanks, or click blank then click option'
Aclass
Brecord
Cstruct
Dinterface
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'record' for record declaration.
Using 'struct' which is a value type, not a record.
2fill in blank
medium

Complete the code to declare a record with positional parameters for Name and Age.

C Sharp (C#)
public record Person([1] string Name, int Age);
Drag options to blanks, or click blank then click option'
Areadonly
Bstatic
Cprivate
Dpublic
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the access modifier, which defaults to private.
Using 'readonly' which is not valid here.
3fill in blank
hard

Fix the error in the record declaration by completing the code.

C Sharp (C#)
public record [1](string Name, int Age);
Drag options to blanks, or click blank then click option'
APerson
Bperson
Cclass
Drecord
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'person' which is not a convention.
Using 'record' or 'class' as the record name.
4fill in blank
hard

Complete the code to declare a record with two properties: Name and Age.

C Sharp (C#)
public [1] Person { string Name { get; init; } int Age { get; init; } }
Drag options to blanks, or click blank then click option'
Arecord
Bclass
C{
D}
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'record'.
Using closing brace '}' instead of opening brace '{' in the second blank.
5fill in blank
hard

Fill all three blanks to declare a positional record with Name and Age properties.

C Sharp (C#)
public [1] Person([2] string Name, int [3]);
Drag options to blanks, or click blank then click option'
Arecord
Bpublic
CAge
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'record'.
Omitting access modifiers for parameters.
Using invalid property names.