was following along an internet course in which they put value after an equals statement. This is pretty hard to google so I came here to get some clarification.
It is the value that is assigned to the PointValue
property. If you declare PointValue = 10
, the set method of the property is called with value = 10
. This comes from Microsoft’s documentation:
The code block for the
get
accessor is executed when the property is read; the code block for theset
orinit
accessor is executed when the property is assigned a value.
1 Like
okay so value is only a struct under the context and body of a set?
Yes, value is only used within the set accessor of a property or an indexer. The value
implicit parameter
1 Like
The property’s code is awfully verbose, nobody writes it this way anymore as followers of the classic “braces, braces everywhere” ideology are going extinct.
It can be rewritten as:
public int PointValue
{
set => _pointValue = value > 0 ? value : 0;
get => _pointValue;
}
Just 5 lines instead of 18!
2 Likes