This documentation is archived and is not being maintained.

Compiler Error CS0821

Visual Studio 2008

Implicitly typed locals cannot be fixed

Implicitly typed local variables and anonymous types are not supported in the fixed context.

To correct this error

  • Either remove the fixed modifier from the variable or else give the variable an explicit type.

The following code generates CS0821:

class A
{
    static int x;

    public static int Main()
    {
        unsafe
        {
            fixed (var p = &x) { }
        }
        return -1;
    }
}
Show: