Remove unread private member (IDE0052)

Property Value
Rule ID IDE0052
Title Remove unread private member
Category CodeQuality
Subcategory Unnecessary code rules
Applicable languages C# and Visual Basic

Overview

This rule flags private fields and properties which have one or more write references, but no read references. This indicates that some parts of code can be refactored or removed to fix maintainability, performance or functional issues. This rule has no associated code style option.

Example

// Code with violations
class C
{
    // IDE0052: Remove unread private members
    private readonly int _field1;
    private int _field2;
    private int Property { get; set; }

    public C()
    {
        _field1 = 0;
    }

    public void SetMethod()
    {
        _field2 = 0;
        Property = 0;
    }
}

// Fixed code
class C
{
    public C()
    {
    }

    public void SetMethod()
    {
    }
}

See also