Do not initialize unnecessarily
Do not initialize unnecessarily
Microsoft docsDescription
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.
Cause
A field of a class is explicitly initialized to the default value of that field's type.
How to fix violations
In most cases, the proper fix is to delete the unnecessary initialization.
In some cases, deleting the initialization may result in subsequent CS0649 warnings being issued due to the field retaining its default value forever. In such cases, a better fix may be to delete the field entirely or replace it with a property:
Example
class C
{
// Violation
int _value1 = 0;
// Fixed
int _value1;
}When to suppress
It is always safe to suppress the warning, as the warning simply highlights potentially unnecessary code and work that may be avoided.