All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.csharp.S4487.html Maven / Gradle / Ivy

There is a newer version: 10.2.0.105762
Show newest version

Why is this an issue?

Private fields which are written but never read are a case of "dead store". Changing the value of such a field is useless and most probably indicates an error in the code.

public class Rectangle
{
  private readonly int length;
  private readonly int width;  // Noncompliant: width is written but never read

  public Rectangle(int length, int width)
  {
    this.length = length;
    this.width = width;
  }

  public int Surface
  {
    get
    {
      return length * width;
    }
  }
}

Remove this field if it doesn’t need to be read, or fix the code to read it.

public class Rectangle
{
  private readonly int length;
  private readonly int width;

  public Rectangle(int length, int width)
  {
    this.length = length;
    this.width = width;
  }

  public int Surface
  {
    get
    {
      return length * width;
    }
  }
}

Resources

Standards





© 2015 - 2024 Weber Informatics LLC | Privacy Policy