Created
February 18, 2025 18:34
-
-
Save jbevain/fd0824e43ad1458cadfa169591299962 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
unsafe class Program | |
{ | |
static void Main() | |
{ | |
IO io = new(42); | |
IOPtr ioPtr = new(&io); | |
Settings(ioPtr); | |
Console.WriteLine(io.Foo); | |
} | |
static void Settings(IOPtr ioPtr) // IDE0060: Parameter 'ioPtr' can be removed; its initial value is never used | |
{ | |
ioPtr.Foo = 12; // IDE0059: Unnecessary assignment of a value to 'ioPtr' | |
} | |
} | |
struct IO(int foo) | |
{ | |
public int Foo = foo; | |
} | |
readonly unsafe struct IOPtr(IO* ptr) | |
{ | |
private readonly IO* _ptr = ptr; | |
public ref int Foo => ref _ptr->Foo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment