Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS0214 

Error Message

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

Community Additions

ADD
Show:
© 2015 Microsoft