閱讀219 返回首頁    go 阿裏雲 go 技術社區[雲棲]


[原創]琢磨一種察看/修改C#堆中東西的方法(隨筆)

namespace cscon
...{
    
class root
    
...{
        
public int i;
        
public int j;

        
/**//*public virtual int nuller(int a,int b)
        {
            return a + b;
        }
*/

    }


    
class Program
    
...{
        
static void Main(string[] args)
        
...{
            
unsafe
            
...{
                root rt 
= new root();
                rt.i 
= 999;
                rt.j 
= 888;
                
fixed (int* i = &rt.i)
                
...{
                    
byte* b = (byte*)i;
                    b 
+= 4;
                    
int* j = (int*)b;
                    Console.WriteLine(
"rt.i:{0},rt.j:{1}", rt.i, rt.j);

                    Console.WriteLine(
"i:addr|{0:x}:{1}", (uint)i, *i);
                    Console.WriteLine(
"i:addr|{0:x}:{1}", (uint)j, *j);
                    (
*j) = 5555;
                    Console.WriteLine(
"i:addr|{0:x}:{1}", (uint)j, *j);
                    Console.WriteLine(
"rt.i:{0},rt.j:{1}", rt.i, rt.j);

                }

            }

            Console.Read();
        }

    }

}

 

最後更新:2017-04-02 00:06:27

  上一篇:go 單身MM創建的廣州易唯翻譯有限公司(www.gzjoyway.com),嘿嘿。。。
  下一篇:go 爆笑!正準備申請吉尼斯的BBS語錄