0

I have a struct with a parameterless constructor:

struct Coordinate
{
    public Coordinate() : this(4, 5, 6)
    {

    }
    public Coordinate(float x, float y, float z)
    {
        X = x;
        Y = y;
        Z = z;
    }

    public float X { get; private set; }
    public float Y { get; private set; }
    public float Z { get; private set; }
}

I have the languate property in the project properties set to C#, but an still getting a compile error.

Error CS0568 Structs cannot contain explicit parameterless constructors
BanksySan
  • 27,362
  • 33
  • 117
  • 216

1 Answers1

1

Sadly C# won't allow defining parameterless constructors. A workaround for it would be to define a default value, as a property.

public static Coordinate defaultValue { get { return new Coordinate (7, 6, 3); } }
dwycxt
  • 41
  • 5