Ошибка компилятора CS0103

Имя "identifier" не существует в текущем контексте

Предпринята попытка использовать имя, которое не существует в классе, пространстве имен или области. Проверьте правильность написания имени и директивы using и ссылки на сборки, чтобы убедиться, что это имя доступно.

Эта ошибка часто возникает при объявлении переменной в цикле или в блоке try или if, если попытаться обратиться к ней из включающего блока кода или отдельного блока кода, как показано в следующем примере.

Примечание.

Эта ошибка также может быть представлена при отсутствии символа greater than в операторе => в лямбда-выражении. Дополнительные сведения см . в лямбда-выражениях.

using System;

class MyClass1
{
    public static void Main()
    {
        try
        {
            // The following declaration is only available inside the try block.
            var conn = new MyClass1();
        }
        catch (Exception e)
        {  
            // The following expression causes error CS0103, because variable
            // conn only exists in the try block.
            if (conn != null)
                Console.WriteLine("{0}", e);
        }
    }
}

Эта ошибка разрешена в следующем примере:

using System;

class MyClass2
{
    public static void Main()
    {
        // To resolve the error in the example, the first step is to
        // move the declaration of conn out of the try block. The following
        // declaration is available throughout the Main method.
        MyClass2 conn = null;
        try
        {
            // Inside the try block, use the conn variable that you declared
            // previously.
            conn = new MyClass2();
        }
        catch (Exception e)
        {
            // The following expression no longer causes an error, because
            // the declaration of conn is in scope.
            if (conn != null)
                Console.WriteLine("{0}", e);
        }
    }
}