Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unhandled exception. System.TypeLoadException: A ByRef-like type cannot be used as the type for an instance field in a non-ByRef-like type.
var line = new Line(new PointStruct(1, 2), new PointStruct(3, 4));
line.Start.Swap();
Console.WriteLine(line);
record struct Line {
private ref PointStruct _start;
private ref PointStruct _stop;
public ref PointStruct Start => ref _start;
public ref PointStruct Stop => ref _stop;
public Line(PointStruct start, PointStruct stop) {
_start = start;
_stop = stop;
}
}
record struct PointStruct {
public int X;
public int Y;
public PointStruct(int x, int y) {
this.X = x;
this.Y = y;
}
public void Swap() => this = new PointStruct(this.Y, this.X);
public override string ToString() => $"({X},{Y})";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment