Compiler Error CS0841

Cannot use variable 'name' before it is declared.

A variable must be declared before it is used.

To correct this error

  • Move the variable declaration before the line where the error occurs.

Example

The following example generates CS0841:

// cs0841.cs
using System;

public class C
{
    public static int Main()
    {
        j = 5; // CS0841
        int j; // To fix, move this line up.
        return 1;
    }
}