Unnecessarily verbose declarations and initializations make it harder to read the code, and should be simplified.
Specifically the following should be omitted when they can be inferred:
new DelegateType new Nullable<Type>
var l = new List<int>() {}; // Noncompliant, {} can be removed
var o = new object() {}; // Noncompliant, {} can be removed
var ints = new int[] {1, 2, 3}; // Noncompliant, int can be omitted
ints = new int[3] {1, 2, 3}; // Noncompliant, the size specification can be removed
int? i = new int?(5); // Noncompliant new int? could be omitted, it can be inferred from the declaration, and there's implicit conversion from T to T?
var j = new int?(5);
Func<int, int> f1 = (int i) => 1; //Noncompliant, can be simplified
class Class
{
private event EventHandler MyEvent;
public Class()
{
MyEvent += new EventHandler((a,b)=>{ }); // Noncompliant, needlessly verbose
}
}
var l = new List<int>();
var o = new object();
var ints = new [] {1, 2, 3};
ints = new [] {1, 2, 3};
int? i = 5;
var j = new int?(5);
Func<int, int> f1 = (i) => 1;
class Class
{
private event EventHandler MyEvent;
public Class()
{
MyEvent += (a,b)=>{ };
}
}