Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0825

Visual Studio 2008

The contextual keyword 'var' may only appear within a local variable declaration.

Implicit typing with the var keyword can only be applied to variables at local method scope.

To correct this error

  • If the variable belongs at class scope, give it an explicit type. Otherwise move it inside the method where it will be used.

The following code generates CS0825 because var is used on a class field:

// cs0825.cs
class Test
{
    private var myField; //CS0825

    static int Main()
    {
        var a = 1; // var is OK here
        return -1;
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft