Challenge - 5 Problems
Record Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Purpose of Records in C#
Why were records introduced in C#?
Attempts:
2 left
💡 Hint
Think about how data objects are compared and how easy it is to create them.
✗ Incorrect
Records were introduced to simplify creating immutable data objects and to provide value-based equality, meaning two records with the same data are considered equal.
❓ Predict Output
intermediate2:00remaining
Output of Record Equality Check
What is the output of this C# code?
C Sharp (C#)
public record Person(string Name, int Age); var p1 = new Person("Alice", 30); var p2 = new Person("Alice", 30); Console.WriteLine(p1 == p2);
Attempts:
2 left
💡 Hint
Records compare data, not references.
✗ Incorrect
Records override equality operators to compare the values of properties, so p1 and p2 are equal because their data matches.
❓ Predict Output
advanced2:00remaining
Immutability Behavior of Records
What will be the output of this C# code?
C Sharp (C#)
public record Point(int X, int Y); var p1 = new Point(1, 2); var p2 = p1 with { X = 3 }; Console.WriteLine($"p1: {p1.X}, {p1.Y}"); Console.WriteLine($"p2: {p2.X}, {p2.Y}");
Attempts:
2 left
💡 Hint
Records support non-destructive mutation with 'with' expressions.
✗ Incorrect
The 'with' expression creates a new record with the changed property, leaving the original unchanged.
🔧 Debug
advanced2:00remaining
Identify the Error in Record Declaration
What error does this C# code produce?
C Sharp (C#)
public record Person(string Name, int Age) { public void Deconstruct(out string name, out int age) { name = Name; age = Age; } public Person(string name) : this(name, 0) { } }
Attempts:
2 left
💡 Hint
Records with primary constructors cannot have explicit constructors without chaining.
✗ Incorrect
You cannot declare an explicit constructor without calling the primary constructor in a record with a primary constructor.
🧠 Conceptual
expert3:00remaining
Why Prefer Records Over Classes for Data Models?
Which reason best explains why records are preferred over classes for data models in C#?
Attempts:
2 left
💡 Hint
Think about how data objects are compared and changed.
✗ Incorrect
Records simplify data modeling by providing value equality and immutability, which helps avoid bugs when comparing or modifying data.