2009-12-02 118 views

回答

0

According to Jon Skeet,有可能通過只是將其轉換爲字節數組。

+0

我需要轉換爲不安全的指針。我做了一個解決方法。通過函數傳遞int。我可以很容易地將byte *轉換爲int並將int轉換爲byte *。 但問題仍在這裏。 – 2009-12-02 22:36:58

+0

@steven i postet jon skets code above ;-) – streetparade 2009-12-02 22:41:03

+0

我發佈了源代碼之後。 – monksy 2009-12-03 03:17:13

4

如何像...

BinaryFormatter bf = new BinaryFormatter(); 
System.IO.MemoryStream ms = new System.IO.MemoryStream(1024); 

Object1 blah = new Object1("Hello"); 

bf.Serialize(ms, blah); 
byte[] bytes = ms.GetBuffer(); 
0

OK,我找到了解決辦法:

(byte*)(int)someObject 
+0

如果someObject大於int,該怎麼辦? – Jan 2009-12-02 22:59:37

+0

在我的情況下,它不會發生。但是,你是對的。 – 2009-12-02 23:06:42

+2

在64位模式下不起作用。指針大於int。 – 2009-12-03 02:17:46