私は 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";
を使用Console.WriteLine(*cp);すると、ポインターアドレスの現在の値が得られます...実際のアドレスを表示したい場合はどうすればよいですか?