I'm looking at some old code and I'm curious if it's appropriate to have logic within the setter property, or if there's a much better way to write this and why? Thank you!
string qBankCode;
string qCode;
public string QBankCode
{
get => qBankCode;
set
{
if (value.Length == 0)
throw new ArgumentException("You need to enter the question bank code as it is mandatory.");
if (value.Length > 30)
throw new ArgumentException("Question bank code cannot exceed 30 characters.");
qBankCode = value;
}
}
public string QCode
{
get => qCode;
set
{
if (value.Length == 0)
throw new ArgumentException("You need to enter the question code as it is mandatory.");
if (value.Length > 30)
throw new ArgumentException("Question code cannot exceed 30 characters.");
qCode = value;
}
}