C#


ROSLYN.PERFORMANCE.CA1805 : Do not initialize unnecessarily (C#)

See Roslyn-Detected C# Warning Classes for more information.

Summary

The .NET runtime initializes all fields of reference types to their default values before running the constructor. In most cases, explicitly initializing a field to its default value in a constructor is redundant, adding maintenance costs and potentially degrading performance (such as with increased assembly size), and the explicit initialization can be removed. In some cases, such as with static readonly fields that permanently retain their default value, consider instead changing them to be constants or properties.

This check corresponds to Roslyn rule CA1805. For full rule details, see the Microsoft website: CA1805.

Properties

Class Name Do not initialize unnecessarily (C#)
Significance reliability
Mnemonic ROSLYN.PERFORMANCE.CA1805
Categories None
Availability Available for C# only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Do not initialize unnecessarily (C#)"

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.