在不安全的上下文中考虑以下代码:
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.