C Sharp (C#) - Properties and Encapsulation
Consider this class with nested validation:
What happens if you assign " " (two spaces) to Id?
class Employee {
private string _id;
public string Id {
get => _id;
set {
if (string.IsNullOrWhiteSpace(value)) throw new ArgumentException("Id required");
if (value.Length != 5) throw new ArgumentException("Id must be 5 chars");
_id = value;
}
}
}What happens if you assign " " (two spaces) to Id?
