C# Error
CS0821 – Implicitly-typed local variables cannot be fixed
Reason for the Error & Solution
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;
}
}