-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Performance.AvoidUnneededFieldInitializationRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Performance
Version: 2.10
This rule looks for constructors that assign fields to their default value (e.g. 0 for an integer, null for an object or a string). Since the CLR zero initializes all values there is no need, under most circumstances, to assign default values. Doing so only adds size to source code and in IL.
Bad example:
public class Bad {
int i;
string s;
public Bad ()
{
i = 0;
s = null;
}
}
Good example:
public class Good {
int i;
string s;
public Good ()
{
// don't assign 'i' since it's already 0
// but we might prefer to assign a string to String.Empty
s = String.Empty;
}
}
- This rule is available since Gendarme 2.2
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!