Compiler Error CS0821

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.

Example

The following code generates CS0821:

class A
{
    static int x;

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

See Also

Reference

Implicitly Typed Local Variables (C# Programming Guide)