You can convert the link to a pointer and then to a number, but this is not a reliable way to track an object in C #, since the garbage collector can change the link at any time. Once you copy the value from the link, you may not know that it still represents the link.
However, you can safely compare the links. As long as the link is still a link, the garbage collector ensures that it is updated. If the garbage collector moves an object, it updates all references to it.
That way, you can safely use the link as an identifier for an object if you hold it with a link. You can compare the two links to see if they point to the same object or not.
If you convert the link value to another form, you get a copy of the flash copy of what the link was at that moment. Although it may be useful to see this value, it is not 100% reliable, i.e. Just because the presentation of the two links is different does not mean that they cannot point to the same object, since the links can be changed between copying the first and second.
So here is how you can get a pointer to an object and convert it to IntPtr :
string str = "asdfasdf"; IntPtr p; unsafe {
source share