CS.METHOD.STRUCT.NO_REF_OUT
Method parameter with struct type has no ref or out specifier.
Method arguments of type struct require a ref or out modifier.
Vulnerability and risk
By default, struct parameters are passed by value. If you intended to pass by reference, expectations and behavior are different.
Mitigation and prevention
Unless there is an explicit reason, for clarity, method arguments of type struct must have a ref or out modifier.
Example
Copy
namespace kmcustom
{
public struct StCoOrds
{
public int x, y;
public StCoOrds(int p1, int p2)
{
x = p1;
y = p2;
}
}
public class ClCoOrds
{
public int x, y;
public ClCoOrds(int p1, int p2)
{
x = p1;
y = p2;
}
}
class C12
{
public void handleStructByValue(int i, ClCoOrds clcoords, StCoOrds stcoords) //NG
{
}
public void handleStructByRef(int i, ref StCoOrds coords) //OK
{
}
public void handleStructByOut(int i, out StCoOrds coords) //OK
{
coords = new StCoOrds(2, 5);
}
}
}