Is there a reason a constructor needs a body in C # if it has an initializer?

It annoys me that I should have them, for example, consider the case

public class IsEquipmentAvailable : Specification<Equipment>
{
    public IsEquipmentAvailable() : base(equipment => equipment.CartEquipments
        .All(o => o.RentState == RentState.Done))
}

However, I am not allowed to write this, as I need to add {}, in C #, which contains at least two additional lines of template code that do nothing. If I want to support calls to the directional expression chain or just create an instance from an expression, it gets even worse.

public class IsEquipmentAvailable : Specification<Equipment>
{
    public IsEquipmentAvailable(Expression<Func<Equipment, bool>> expression) 
        : base(expression)
    {
    }

    public IsEquipmentAvailable(ISpecification<Equipment> specification) 
        : base(specification)
    {
    }

    public IsEquipmentAvailable() : base(equipment => equipment.CartEquipments
        .All(o => o.RentState == RentState.Done))
    {
    }
}

The functional part of programming laughs at me from ignorance, because he does not know better. Sometimes there are good reasons why everything is as it is, so I would like to know what is behind it.

+4
source share
1 answer

- , (10.11.1):

( , object)

, () . ,

C(...) {...}

C(...): base() {...}

, , , , , .


, , - , , - , , , - , extern, , abstract. , .

+2

All Articles