Created
July 13, 2022 10:39
-
-
Save sonnemaf/a4493c7c40be4ae2b0c1f3df6ee80165 to your computer and use it in GitHub Desktop.
Unhandled exception. System.TypeLoadException: A ByRef-like type cannot be used as the type for an instance field in a non-ByRef-like type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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