Back to questions
JuniorTheoryVery common
What does the program print (lines separated by spaces)?
var a = new Pass(7);
var b = new Pass(7);
var c = new Card();
var d = new Card();
Console.WriteLine(a == b);
Console.WriteLine(c == d);
record Pass(int Room);
class Card { public int Room = 7; }True False
- Expecting
Falsefor the records: a record is a reference type, but its==compares every property, so twoPass(7)records are equal. - Expecting
Truefor the class objects: for a class,==compares references, and twonew Card()are separate objects even with equal fields.
- What does
Console.WriteLine(a)print for the recorda? - What would
c == dprint afterd = c;?