Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0214

Pointers may only be used in an unsafe context

Pointers can only be used with the unsafe keyword.

The following sample generates CS0214:

// CS0214.cs
public struct S
{
   public int a;
}

public class a
{
   public static int Main()
   // try the following line instead
   // unsafe public static int Main()
   {
      S s = new S();
      S * s2 = &s;    // CS0214
      s2->a = 3;      // CS0214

      return 1;
   }
}
Show:
© 2015 Microsoft