C#

C#

By DeepSource

Getters and setters with a single statement in their bodies can be simplified CS-R1095

Anti-pattern

Getters and setters with a single statement in their bodies can be simplified using the arrow operator (=>). This eliminates the need for braces, thereby reducing the indentation and lines used.

Examples

Bad Practice

public int Age
{
    get
    {
        return _age;
    }

    set
    {
        _age = value;
    }
}

Recommended

public int Age
{
    get => _age;
    set => _age = value;
}

Reference