Personally, I would suggest using struct here, which is much more applicable for what you are trying to do (plus you can customize the internal layout if you need to). For example, with struct Foo and a field of reference type foo :
unsafe void Bar() { fixed (Foo* ptr = &foo)
Note: if foo is a local variable, then it is on the stack and should not even be fixed :
unsafe void Bar() { Foo foo = new Foo(); Foo* ptr = &foo;
source share