相关疑难解决方法(0)

不能取给定表达式C#指针的地址

在不安全的上下文中考虑以下代码:

string mySentence = "Pointers in C#";

fixed (char* start = mySentence) // this is the line we're talking about
{
    char* p = start;

    do
    {
        Console.Write(*p);
    }
    while (*(++p) != '\0');
}

Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

这很好用.

根据http://msdn.microsoft.com/en-us/library/f58wzh21(v=VS.100).aspx我应该能够替换我标记的行

fixed(char* start = &mySentence[0])
Run Code Online (Sandbox Code Playgroud)

但不幸的是VS给了我以下错误.

无法获取给定表达式的地址

这个错误在我身边吗?

VS.NET 2010 Premium.

c# pointers

5
推荐指数
1
解决办法
6099
查看次数

标签 统计

c# ×1

pointers ×1