获取数组中第一个条目的指针 [英] Getting pointer for first entry in an array

查看:87
本文介绍了获取数组中第一个条目的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取数组中第一个条目的指针.这就是我尝试的方式

I want to get pointer of first entry in the array. This is how I tried

int[] Results = { 1, 2, 3, 4, 5 };

unsafe
{
    int* FirstResult = Results[0];
}

获取以下编译错误.有任何解决方法的想法吗?

Get following compilation error. Any ideas how to fix it?

您只能将未固定表达式的地址放在 固定语句初始化程序

You can only take the address of an unfixed expression inside of a fixed statement initializer

推荐答案

错误代码很容易获得答案-搜索错误代码(在您的情况下为CS0212),在很多情况下,您都可以通过建议的修复程序获得解释.

The error codes are magic to get the answer - search for error code (CS0212 in your case) and you get explanation with proposed fix in a lot of case.

搜索: http://www.bing.com/search?q=CS0212+ msdn

结果: http://msdn.microsoft.com/en -us/library/29ak9b70%28v = vs.90%29.aspx

页面中的代码:

   unsafe public void mf()
   {
      // Null-terminated ASCII characters in an sbyte array 
      sbyte[] sbArr1 = new sbyte[] { 0x41, 0x42, 0x43, 0x00 };
      sbyte* pAsciiUpper = &sbArr1[0];   // CS0212
      // To resolve this error, delete the previous line and 
      // uncomment the following code:
      // fixed (sbyte* pAsciiUpper = sbArr1)
      // {
      //    String szAsciiUpper = new String(pAsciiUpper);
      // }
   }

这篇关于获取数组中第一个条目的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆