0

I have the following constructors:

public Class1()
{
    this.Variable = new Variable();
}

public Class1(Variable vari)
{
    this.Variable = vari;
}

Which can be rewritten as:

public Class1()
    : this(new Variable())
{

}

public Class1(Variable vari)
{
    this.Variable = vari;
}

Is there any benefit from writing it the second way or would they be practically the same?

1 Answer 1

5

The first one duplicates logic. Even if said logic consists of a single assignment statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.