c# - Getting the address location of variable -


in c# how can address of variable without using unsafe keyword. not want change address or access it, have location.

you have pin object before extracting address. otherwise, gc free move around.

object variable = new object(); gchandle handle = gchandle.alloc(variable, gchandletype.pinned); intptr address = handle.addrofpinnedobject(); 

normally in scenarios requiring type of unmanaged interop. however, there need type of manual manipulation.


Comments