Challenge - 5 Problems
Record Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple record declaration
What is the output of this C# program using a record declaration?
C Sharp (C#)
public record Person(string Name, int Age); class Program { static void Main() { var p = new Person("Alice", 30); System.Console.WriteLine(p); } }
Attempts:
2 left
💡 Hint
Records override ToString() to show property names and values.
✗ Incorrect
In C#, records automatically generate a ToString() method that outputs the record type name and its properties with their values in the format: TypeName { Property1 = value1, Property2 = value2 }.
❓ Predict Output
intermediate2:00remaining
Output of record with inheritance
What is the output of this C# program with record inheritance?
C Sharp (C#)
public record Animal(string Name); public record Dog(string Name, string Breed) : Animal(Name); class Program { static void Main() { var d = new Dog("Buddy", "Beagle"); System.Console.WriteLine(d); } }
Attempts:
2 left
💡 Hint
Derived records include all properties in ToString output.
✗ Incorrect
The derived record Dog inherits from Animal and adds Breed. The ToString() method shows all properties from both records.
🔧 Debug
advanced2:00remaining
Identify the syntax error in record declaration
Which option contains a syntax error in the record declaration?
Attempts:
2 left
💡 Hint
Check the separator between parameters in the record declaration.
✗ Incorrect
In C#, record positional parameters must be separated by commas, not semicolons. Option A uses semicolons, causing a syntax error.
❓ Predict Output
advanced2:00remaining
Output of record with custom ToString override
What is the output of this C# program with a record that overrides ToString()?
C Sharp (C#)
public record Point(int X, int Y) { public override string ToString() => $"({X}, {Y})"; } class Program { static void Main() { var pt = new Point(3, 4); System.Console.WriteLine(pt); } }
Attempts:
2 left
💡 Hint
The record overrides ToString to return a custom string.
✗ Incorrect
The overridden ToString() method returns the coordinates in parentheses, so the output is (3, 4).
🧠 Conceptual
expert2:00remaining
Number of properties in a record with inheritance
Given these record declarations, how many properties does the record 'Employee' have?
C Sharp (C#)
public record Person(string Name, int Age); public record Employee(string Name, int Age, string Position) : Person(Name, Age);
Attempts:
2 left
💡 Hint
Count all positional parameters from base and derived records.
✗ Incorrect
Employee inherits Name and Age from Person and adds Position, so it has 3 properties total.