Код: Выделить всё
public record MyRecord {
// All truely immutable properties
public int ThisAndManyMoreComplicatedProperties { get; init; }
// ...
// Compute only when required, but then cache it
public string Hash {
get {
if (hash == null)
hash = ComputeHash();
return hash;
}
}
private string? hash = null;
}
Код: Выделить всё
MyRecord myRecord = ...;
var changedRecord = myRecord with { AnyProp = ... };
Код: Выделить всё
changedRecordЛюбой шанс отметьте поле хэша как «переходное»/«внутреннее»/«действительно личное»… или мне придется написать свой собственный конструктор копирования, чтобы имитировать эту функцию?
Подробнее здесь: https://stackoverflow.com/questions/661 ... p-9-record
Мобильная версия