Home > Article > Backend Development > In C#, retrieve data value as pointer
A pointer is a variable whose value is the address of another variable. Use the ToString() method to retrieve the data stored at the location referenced by the pointer variable.
The following is an example -
using System; namespace UnsafeCodeApplication { class Program { public static void Main() { unsafe { int var = 100; int* p = &var; Console.WriteLine("Data is: {0} " , var); Console.WriteLine("Data is: {0} " , p->ToString()); Console.WriteLine("Address is: {0} " , (int)p); } Console.ReadKey(); } } }
The above operation requires you to set unsafe command line options. After the setup is complete, the following output will be displayed.
Data is: 100 Data is: 100 Address is: 77678547
The above is the detailed content of In C#, retrieve data value as pointer. For more information, please follow other related articles on the PHP Chinese website!