C Sharp (C#) - Properties and Encapsulation
Consider this C# class snippet:
class Person {
private int age;
public int Age {
get => age;
set {
if (value < 0) throw new ArgumentException("Age cannot be negative");
age = value;
}
}
}
What happens if you run this code?
var p = new Person();
p.Age = -5;
