I created a structure pointer, but each call to a new node returns the same address. But I was expecting a different address to be returned for each call to the new node. Can anybody help?
public unsafe struct Node
{
public int Data;
}
class TestPointer
{
public unsafe Node* getNode(int i)
{
Node n = new Node();
n.Data = i;
Node* ptr = &n;
return ptr;
}
public unsafe static void Main(String[] args)
{
TestPointer test = new TestPointer();
Node* ptr1 = test.getNode(1);
Node* ptr2 = test.getNode(2);
if (ptr1->Data == ptr2->Data)
{
throw new Exception("Why?");
}
}
}
source
share