B
Berryl Hesh
I am trying to eliminate duplicate logic in some loops, an example of which
is below
Both of the loops below are iterating over the same list. The thing that
varies is the method that counts different properties of the same class.
Each method has the same signature.
I am thinking I can have one count method that is passed a delegate for
either AppointmentCount() or ImplementationCount() but I don't know how to
set it up.
Thanks for your help!
public override int AppointmentCount() {
var total = 0;
foreach (var activity in ChildrenList)
total += activity.AppointmentCount();
return total;
}
public virtual int AppointmentCount() { return
_scheduledResourceAllocations.Count; }
public override int ImplementationCount() {
var total = 0;
foreach (var activity in ChildrenList)
total += activity.ImplementationCount();
return total;
}
public virtual int ImplementationCount() { return
_implementedResouceAllocations.Count; }
is below
Both of the loops below are iterating over the same list. The thing that
varies is the method that counts different properties of the same class.
Each method has the same signature.
I am thinking I can have one count method that is passed a delegate for
either AppointmentCount() or ImplementationCount() but I don't know how to
set it up.
Thanks for your help!
public override int AppointmentCount() {
var total = 0;
foreach (var activity in ChildrenList)
total += activity.AppointmentCount();
return total;
}
public virtual int AppointmentCount() { return
_scheduledResourceAllocations.Count; }
public override int ImplementationCount() {
var total = 0;
foreach (var activity in ChildrenList)
total += activity.ImplementationCount();
return total;
}
public virtual int ImplementationCount() { return
_implementedResouceAllocations.Count; }