C# 7.2 added readonly structs and the in modifier for method parameters. However, you get a compiler error when you try to use these structs with reference-like semantics in lambda expressions:
public readonly struct Point {
public Struct(int x, int y) {
X = x;
Y = y;
}
public int X { get; }
public int Y { get; }
}
public IEnumerable<Point> FindMatching(
this IEnumerable<Point> points,
in Point toMatch) {
return point.Where(p => p.X == point.X && p.Y == point.Y);
}
Compiling returns an error:
error CS1628: Cannot use ref or out parameter 'toMatch' inside an anonymous method, lambda expression, or query expression.
It's not a ref or out parameter, however.
ref/outhere. It is asking specifically about a C# 7.2 feature, so an answer from 2009 cannot possibly answer this directlyref/outin a lambda. The answer to "why does it complain aboutref/outwhen I usein" is simply: becauseinis actually aref. Pointing to that answer simply doesn't answer that. Especially given that the compiler message is very confusing and doesn't help here. I'd agree that they're strongly related questions, but they're not the same.