가 :간단한 유형의 직렬화가 왜 그렇게 복잡한가요? 다음 코드를 실행할 때
int myInt = 13;
object myObj = myInt;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bf.Serialize(ms, myObj);
byte[] myByteArray = ms.ToArray();
당신이 길이가 54 바이트 배열을 얻을 - 당신이 4 바이트 길이의 배열을하지 않는 이유를 이해하지 않습니다.
int 변수 (객체 변수 대신)를 다음과 같이 직렬화하려고해도 : bf.Serialize (ms, myInt);
같은 결과가 나타납니다. 내 목표는 바이트 배열에 다른 유형 (INT32, INT16, 등 ...) 변환하는 것입니다 그것은 컴파일하지 않기 때문에, 따라서 나는
BitConverter.GetBytes(myObj);
을 사용할 수 없습니다
Error 1 The best overloaded method match for 'System.BitConverter.GetBytes(bool)' has some invalid arguments...
분명하다 왜냐하면 컴파일러는 명시 적으로 명시하지 않고 객체를 다른 것으로 변환 할 수 없으므로 ...
내가 뭘 잘못하고 있니?