Our Program class will create 2 delegates to execute the calculation. The first delegate will be named and the second one will be anonymous.

The first method is named and called CalculateStandardCharge. It will multiply the amount withdrawn by 1% and return that value as the Service Charge.

The next method, ServiceChargeCalculation will use the delegate stored in the Withdrawal object to perform the calculation.

In our Main method we will set a risk factor which increases the amount of the charge, for example, we could increase the charge based on the amount withdrawn. NOTE: Within the ServiceChargeCalculation method the risk factor is known even though the variable is outside the scope of the method. Search for ‘captured Outer Variable’ for more information about this term.

The standard_charge delegate is an example of a named method.

The highRisk_charge delegate is an example of a anoymous method and describes an alternate calculation method.

The first foreach statement (Calculate the charge for all Withdrawals) calculates the charge using the method provided when we populated the Withdrawls class. Either the standard_charge delegate or the highRisk_charge delegate. The program thereby knows which function to use at runtime, I.e. we pass the method/delegate as a parameter.

Lastly, we display the output on the console. The same could eaisly be stored in a database or logged in a flat file for later backend processing.