Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1008 Bytes

cs0825.md

File metadata and controls

41 lines (32 loc) · 1008 Bytes
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Compiler Error CS0825
Compiler Error CS0825
07/20/2015
CS0825
CS0825
49393d23-ec5f-4b44-a3fd-7e0a95ac0edd

Compiler Error CS0825

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

To correct this error

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

Example

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

// cs0825.cs  
class Test  
{  
    // Both of these declarations trigger CS0825
    private var genreName;
    private var bookTitles = new List<string>();
  
    static int Main()  
    {  
        var totalBooks = 42; // var is OK here  
        return -1;  
    }  
}  

See also