Skip to content

Instantly share code, notes, and snippets.

Created July 13, 2022 10:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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));
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