Bitterblue
Bitterblue

Reputation: 14075

C# - Change Default Of A Struct?

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:

I 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.


Answer: No.

Suggested solutions:

Upvotes: 2

Views: 129

Answers (1)

Sebastian Negraszus
Sebastian Negraszus

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

Related Questions