Code inspection: Struct can be made readonly
This inspection reports a struct whose instance state is never mutated and which can therefore be declared as readonly. Marking such structs as readonly makes the intent explicit and helps avoid defensive copies.
Example
public struct Point
{
private readonly int _x;
private readonly int _y;
public Point(int x, int y)
{
_x = x;
_y = y;
}
public int Sum() => _x + _y;
}
public readonly struct Point
{
private readonly int _x;
private readonly int _y;
public Point(int x, int y)
{
_x = x;
_y = y;
}
public int Sum() => _x + _y;
}
Quick-fix
Add the readonly modifier to the struct declaration.
29 March 2026