I use SonarLint for Visual Studio 2022 and installed SonarLint in my company.
I don’t understand why properties can’t use public in structure types of C#?
(not class, more similar example in Microsoft Learn)
Why must use private?
Rule S1104 is called “Fields should not have public accessibility”. The complaint is about the field being public. To fix the issue, turn your fields into auto-properties:
public struct Coord
{
public int X { get; } // A struct should be read-only if possible.
public int Y { get; set; } // Make it read-write only if you know the implications for structs.
}
Another option is to mark your public fields as read-only:
public struct Coord
{
public readonly int x;
public readonly int y;
}