← back to index

S2292 — Trivial properties should be auto-implemented

Language: C#  |  Type: CODE_SMELL  |  Severity: Minor

Tags: clumsy

Why is this an issue?

Trivial properties, which include no logic but setting and getting a backing field should be converted to auto-implemented properties, yielding cleaner and more readable code.

Noncompliant code example

public class Car
{
  private string _make;
  public string Make // Noncompliant
  {
    get { return _make; }
    set { _make = value; }
  }
}

Compliant solution

public class Car
{
  public string Make { get; set; }
}