unsafe  private void seekbyte()
{
bs[0]=100;

fixed ( byte* p =&bs[0])//再使用bs过程中必须固定bs否则会被回收器移动
{
IntPtr ptr=new IntPtr (p);

}
}

解决方案 »

  1.   

    unsafe  private void seekbyte()
    {
    bs[0]=100;          bs[1]=200;

    fixed ( byte* p =&bs[0])//再使用bs过程中必须固定bs否则会被回收器移动
    {
    IntPtr ptr=new IntPtr (p);
                                         this.textBox1 .Text =p[1].ToString ();

    }
    }
      

  2.   

    需要使用不安全代码,不大熟悉
    大概是
    System.IntPtr ptr; 
    byte [] b1=new byte[400];
    unsafe
    {
        //这儿可以进行指针操作
    }具体怎么做在网上搜一下吧,关键字unsafe
      

  3.   

    具体情况时:b1是从文件读出的字节流:
    FileInfo fi=new FileInfo("aa");
    FileStream fs=fi.OpenRead();
    int nBytesRead;
    System.IntPtr ptr; 
    byte [] b1=new byte[400]; 
    nBytesRead=fs.Read(ah,0,400);
    fs.Close();
    而 Bitmap(int a1, int a2, int a2, PixelFormat a3, IntPtr ptr);
    中的ptr就是对应文件读出的b1内容:
    如何使ptr是b1的指针地址或b1如何用指针ptr来表示?
      

  4.   

    Bitmap(int a1, int a2, int a2, PixelFormat a3, IntPtr ptr);
    改为:
    Bitmap(int a1, int a2, int a3, PixelFormat a4, IntPtr ptr);
      

  5.   

    nBytesRead=fs.Read(ah,0,400);
    改为:
    nBytesRead=fs.Read(b1,0,400);
      

  6.   

    byte* p =&bs[0];
    IntPtr ptr=new IntPtr (p);
    应该可以的
      

  7.   

    有.net帮你托管代码不要,干吗要用不安全代码呢?这不回到vc了吗?
      

  8.   

    to liuzhonghe(呆头鹅):有好办法,能详细点?
      

  9.   

    实际上只要指向数组的开始就可以了:
    unsafe {
    System.IntPtr ptr; 
    byte [] b1=new byte[400];
    fixed (void * ii = b1) {
    ptr = new IntPtr(ii);
    }
    }
      

  10.   

    IntPtr dd;
    unsafe
    {
      fixed (byte* p =&file_content[0])
      {
    dd=new IntPtr (p);
      }
    }
      

  11.   

    上面搞错了:
    应为:
    FileInfo fi=new FileInfo("aa");
    FileStream fs=fi.OpenRead();
    int nBytesRead;
    System.IntPtr ptr; 
    byte [] b1=new byte[400]; 
    nBytesRead=fs.Read(b1,0,400);
    fs.Close();
    IntPtr dd;
    unsafe
    {
      fixed (byte* p =&b1[0])
      {
        dd=new IntPtr (p);
      }
    }
    成功!
    谢谢各位!