Reputation: 14075
Asked simple: Can I change the default
of a struct
?
Point
or PointF
return x = 0
and y = 0
but I would like to make it return x = -1
and y = -1
. Reason:
x = 0
and y = 0
is in my application a valid valuex = -1
and y = -1
is in my application an invalid valueI would like to return just an invalid value when I can't compute a valid one. I could define a const
but that would be a few in all classes that are involved in calculation of Points.
Suggested solutions:
struct
→ class
and init values with -1
, instead of default()
use new TheClass()
Upvotes: 2
Views: 129
Reputation: 12195
Structs cannot override the parameterless default constructor, nor can they explicitly initialize their fields.
What you could do is use nullable points Point?
and use null for invalid values.
Upvotes: 1