Retrieve data value as a pointer in C#

CsharpProgrammingServer Side Programming

A pointer is a variable whose value is the address of another variable. Retrieve the data stored at the located referenced by the pointer variable, using the ToString() method.


Here in 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);


Above will require you to set unsafe comman line option. After seeting it, the following output would be visible.

Data is: 100
Data is: 100
Address is: 77678547
Updated on 22-Jun-2020 07:50:46