Skip to main content

Redundant else statement

In This Article

CodeRush Classic shows the Redundant else statement code issue if an else block is empty.

#Fix

Remove the empty else block.

#Purpose

Highlights the empty else, which can be removed to improve code readability.

#Example

public string Text 
{
    get { return _Text; }
    set
    {
        if (!String.IsNullOrEmpty(_Text))
        {
            ProcessText(value); 
            _Text = value;
        }else
        {

        }
    }
}

Fix:

public string Text 
{
    get { return _Text; }
    set
    {
        if (!String.IsNullOrEmpty(_Text))
        {
            ProcessText(value); 
            _Text = value;
        }
    }
}