2010-06-18 47 views

回答

2

的地址指针的对象的引用如果你愿意用unsafe代码,你可以使用pointers。下面是MSDN一个例子:

// assume class Point { public int x, y; } 
// pt is a managed variable, subject to garbage collection. 
Point pt = new Point(); 
// Using fixed allows the address of pt members to be 
// taken, and "pins" pt so it isn't relocated. 
fixed (int* p = &pt.x) 
{ 
    *p = 1; 
} 

但是你应该避免这样做,除非你知道你在做什么,知道你为什么需要这个功能。

+0

Thanx 4回复......但我想在C#中使用这段代码 – 2010-06-18 08:46:41

+0

@vishal_niist:我发布*的代码是*在C#中。 – 2010-06-18 08:51:03

相关问题