Is it possible to change the memory address of an object in C# ? Example of what I want:
unsafe public Program {
public struct Foo
{
int a;
int b;
}
static void Main(string[] args){
Foo foo= new Foo();
fixed(Foo *foo_ptr=&foo) //I know I can get the object pointer here.
Foo foo2= new Foo();
fixed(&foo2=foo_ptr) //How I can do this?
}
}
I got this error when I tried the last fixed
:
You can only take the address of an unfixed expression inside of a fixed statement initializer csharp(CS0212)
Can someone help me? Thanks.
Edit:
There is long story why I want change the memory address and not just writing that foo2=foo;
. That is why I am wondering if it is possible or not? This post is not what I am asking