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

Record declaration syntax in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Record Syntax Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
AName: Alice, Age: 30
BAlice 30
CPerson(Alice, 30)
DPerson { Name = Alice, Age = 30 }
Attempts:
2 left
💡 Hint
Records override ToString() to show property names and values.
Predict Output
intermediate
2: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);
    }
}
ADog { Name = Buddy, Breed = Beagle }
BAnimal { Name = Buddy }
CDog(Buddy, Beagle)
DBuddy Beagle
Attempts:
2 left
💡 Hint
Derived records include all properties in ToString output.
🔧 Debug
advanced
2:00remaining
Identify the syntax error in record declaration
Which option contains a syntax error in the record declaration?
Apublic record Car(string Make; string Model);
Bpublic record Car(string Make, string Model);
Cpublic record Car(string Make, string Model) {}
Dpublic record Car { string Make; string Model; }
Attempts:
2 left
💡 Hint
Check the separator between parameters in the record declaration.
Predict Output
advanced
2: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);
    }
}
A3, 4
BPoint { X = 3, Y = 4 }
C(3, 4)
DPoint(3, 4)
Attempts:
2 left
💡 Hint
The record overrides ToString to return a custom string.
🧠 Conceptual
expert
2: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);
A2
B3
C4
D1
Attempts:
2 left
💡 Hint
Count all positional parameters from base and derived records.