Home >Backend Development >C#.Net Tutorial >In C#, retrieve data value as pointer

In C#, retrieve data value as pointer

PHPz
PHPzforward
2023-09-21 21:49:031413browse

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.

Example

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();
      }
   }
}

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete