Skip to main content

Undeclared element

In This Article

CodeRush Classic shows the Undeclared element code issue if the current code element is not declared.

#Fix

Declare the code element.

#Purpose

Highlights the code elements, which would cause the The name ‘Element name’ does not exist in the current context compilation error.

#Example

public class MyClass
{
    public void AddText(string text)
    {
        if (_Data == null)
            _Data = new List<string>();
        _Data.Add(text);
    }
}

Fix:

public class MyClass
{
    private List<string> _Data = null;
    public void AddText(string text)
    {
        if (_Data == null)
            _Data = new List<string>();
        _Data.Add(text);
    }
}