[Obfuscation(Feature = "ultra", Exclude = false)]
public unsafe class UnsafeClass
{
public void UnsafeMethod()
{
int* ptr = stackalloc int[1];
*ptr = 42;
Console.WriteLine("Unsafe method: " + *ptr);
}
}
Type “System.IntPtr” cannot cast to “System.Int32&”
Below works fine.
public static unsafe void unsafe2()
{
Console.WriteLine("Unsafe2");
int* pointer = stackalloc int[10];
for (int i = 0; i < 10; i++)
{
pointer[i] = i;
}
Console.WriteLine($"Stackalloc result: {pointer[5]}");
}