ou decide to use the Salary delegate to invoke these methods.

You have been given the responsibility of creating a class named CalcSalary that will determine the salaries of Domain.com’s staff.
The CalcSalary class includes methods to increment and decrement staff salaries.
You would like to invoke the IncrementSalary and DecrementSalary methods dynamically at runtime from the sales manager application when needed.
After viewing the information displayed in the exhibit, you decide to use the Salary delegate to invoke these methods.
using System;
public delegate bool Salary (Employee Emp, double Amount); public class CalcSalary {
// for promotions

You have been given the responsibility of creating a class named CalcSalary that will determine the salaries of Domain.com’s staff.

The CalcSalary class includes methods to increment and decrement staff salaries.
You would like to invoke the IncrementSalary and DecrementSalary methods dynamically at runtime from the sales manager application when needed.

After viewing the information displayed in the exhibit, you decide to use the Salary delegate to invoke these methods.

using System;
public delegate bool Salary (Employee Emp, double Amount); public class CalcSalary {
// for promotions

A.
public void Review (Employee emp, double amount){
Salary salaryDel;
if (emp.Status == QuarterlyReview.OnTarget || emp.Status == QuarterlyReview.AboveGoals)
salaryDel.Invoke (CalcSalary.IncrementSalary (emp, amount)); else
salaryDel.Invoke (CalcSalary.DecrementSalary (emp, amount)); }

B.
public void Review (Employee emp, double amount){
Salary salaryDel;
if (emp.Status == QuarterlyReview.OnTarget || emp.Status == QuarterlyReview.AboveGoals)
salaryDel.Method = CalcSalary.IncrementSalary;
else
salaryDel.Method = CalcSalary.DecrementSalary;
salaryDel.Invoke (emp, amount);
}

C.
public void Review (Employee emp, double amount){
Salary salaryDel;
if (emp.Status == QuarterlyReview.OnTarget || emp.Status == QuarterlyReview.AboveGoals)
salaryDel.IncrementSalary (emp, amount);
else
salaryDel.DecrementSalary (emp, amount);
}

D.
public void Review (Employee emp, double amount){
Salary salaryDel;
if (emp.Status == QuarterlyReview.OnTarget || emp.Status == QuarterlyReview.AboveGoals)
salaryDel = CalcSalary.IncrementSalary;
else
salaryDel = CalcSalary.DecrementSalary;
salaryDel.Invoke (emp, amount);
}

Explanation:

This code declares a delegate variable and, based upon the value of the Status property, assigns the delegate variable to the correct method. If the Status property is QuarterlyReview.OnTarget or QuarterlyReview.AboveGoals, then the Salary delegate variable is assigned to the IncrementSalary method of the CalcSalary class. If not, then the Salary delegate variable is assigned to the DecrementSalary method of the CalcSalary class. Delegates are method pointers and must be assigned to a method so that a delegate variable can invoke it. The Invoke method takes those arguments specified by the delegate declaration.

Incorrect Answers:
A, B, C: You should not use these code fragments because they are syntactically incorrect and will result in a compilation error if used.



Leave a Reply 0

Your email address will not be published. Required fields are marked *