Recently started working in C# and I am making full use of the shorthand properties (Getters-Setters) and have a question about how to constrain the setter
I have a height property as follows
public int height {get; set;} = 200
The width property however has a minimum of 10px and is thus written in the original form
private int width = 100
public int Width
{
get
{
return this.width;
}
set
{
this.width = value > 10 ? value : 10;
}
}
My question is... Is there any way to keep the shorthand styled property yet manipulate it to have my ternary operator? Nearly all the other properties have the shorthand syntax and I like being consistent. (I know this is wrong but is something along the lines of this possible?)
public int width {get; set => value > 10 ? value : 10;} = 100