Skip to content

Instantly share code, notes, and snippets.

@jbevain
Created February 18, 2025 18:34
Show Gist options
  • Save jbevain/fd0824e43ad1458cadfa169591299962 to your computer and use it in GitHub Desktop.
Save jbevain/fd0824e43ad1458cadfa169591299962 to your computer and use it in GitHub Desktop.
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