C# Pointers (.Net)

You are unlikely to use pointers when writing managed .Net code, but we include this short demo for completeness so that you can compare the syntax with the Pascal original. You need to change the settings to enable blocks of unsafe C# code to compile. In SharpDevelop, select menu item Project > Project Options... then the Compiling tab and check the Allow Unsafe code checkbox:

Allow Unsafe code

Allow Unsafe code

With RemObjects C#, change the relevant Boolean value in the .hydrogene project file to true:
<AllowUnsafeCode>True</AllowUnsafeCode>

A copy of the (minimal) output follows the code of the demonstration.

using System;

namespace pointer_demo_cs
{
  static class Program
  {
    public static void Main(string[] args)
    {
      int int1, int2;
      int1 = 42;
      unsafe
      {
        int* ptrInt = &int1;
        int2 = *ptrInt;       
      }
      Console.WriteLine("int2: " + int2.ToString());
      Console.ReadLine();
    }
  }
}


Output:
int2: 42

Programming - a skill for life!

C# Demonstrations of I/O, arrays, methods, classes, loops, enums, pointers, file handling, Firebird databases, LINQ and drawing on a form