new Title("hi") == new Title("hi") // truenew Title("hi") == new Title("bye") // false
The same applies for private properties
1
2
3
4
5
6
7
publicrecordTitle{
privatestring title {get; set;}
public Title(string title){
this.title = title;
}
}
I’m note 100% sure how I feel about this. It does allow types, as above, to retain value equality without exposing their internal values. This is a case I encounter often.
At the same time, it could cause unintuitive inequality. Two instances of a type could appear to be the same because all their public values match, but still not be equal because of hidden values. I can picture this causing a debugger great confusion.
1
2
3
4
5
6
7
8
9
10
publicrecordMixedAccessLevels{
// consumers can only inspect `visible`privatestring invisible {get; set;}
publicint visible {get; set;}
public Title(string invisible, int visible){
this.invisible = invisible;
this.visible = visible;
}
}