Ben*_*ter 15 c# pointers unsafe
自从我用C#编程以来,我没有做过任何指示 - 而且很久以前我的C++时代.我以为我应该刷新我的知识,因为这里有另一个问题,我只是在玩它们.我理解他们都没关系,但我无法弄清楚如何将指针的地址写入控制台......
char c = 'c';
char d = 'd';
char e = 'e';
unsafe
{
char* cp = &d;
//How do I write the pointer address to the console?
*cp = 'f';
cp = &e;
//How do I write the pointer address to the console?
*cp = 'g';
cp = &c;
//How do I write the pointer address to the console?
*cp = 'h';
}
Console.WriteLine("c:{0}", c); //should display "c:h";
Console.WriteLine("d:{0}", d); //should display "d:f";
Console.WriteLine("e:{0}", e); //should display "e:g";
Run Code Online (Sandbox Code Playgroud)
使用Console.WriteLine(*cp);给我指针地址的当前值...如果我想显示实际地址怎么办?
| 归档时间: |
|
| 查看次数: |
8027 次 |
| 最近记录: |