Compiler Error CS0214

Pointers and fixed size buffers may only be used in an unsafe context

Pointers can only be used with the unsafe keyword. For more information, see Unsafe Code and Pointers (C# Programming Guide).

The following sample generates CS0214:

// CS0214.cs
// compile with: /target:library /unsafe
public struct S
{
   public int a;
}

public class MyClass
{
   public static void Test()
   {
      S s = new S();
      S * s2 = &s;    // CS0214
      s2->a = 3;      // CS0214
      s.a = 0;
   }

   // OK
   unsafe public static void Test2()
   {
      S s = new S();
      S * s2 = &s;
      s2->a = 3;
      s.a = 0;
   }
}