Is there a way to serialize and deserialize a pointer in C#?
Is it possible to serialize or deserialize any pointer? Suppose I have a class as follows
public unsafe class Class001
{
public byte* pointer;
public Class001()
{
var byteArr = new byte[] {12, 54, 20};
fixed(byte* ptr开发者_StackOverflow社区 = byteArr)
{
pointer = ptr;
}
}
}
Can I store the hex value of pointer in a file and reconstruct it using Reflection by reading the file?
I used the word serialization/deserialization just to denote saving some values in a file and reconstruct it later, it need not to be any standard serialization process.
Absolutely not! A pointer is a reference to a particular memory location. You may indeed serialize the hex value of that particular memory address - but when you deserialize it, that memory address will certainly contain something entirely different.
精彩评论