Maha

Maha

  • NA
  • 0
  • 326.2k

NP115 method header is becoming data type

Aug 8 2008 9:51 AM

Hi Guys

 

NP115 method header is becoming data type

 

In the following callback program method header is becoming data type (highlighted in yellow). And parameter is becoming method (highlighted in green) I wish to know the reason for that. Please explain the reason.

 

Thank you

 

using System;

 

namespace MyCompany

{

    public class Employee

    {

        private string firstName;

        private string lastName;

        private decimal salary;

 

        public Employee(string first, string last, decimal salary)

        {

            this.firstName = first;

            this.lastName = last;

            this.salary = salary;

        }

 

        public string FirstName

        {

            get { return firstName; }

            set { firstName = value; }

        }

        public string LastName

        {

            get { return lastName; }

            set { lastName = value; }

        }

        public decimal Salary

        {

            get { return salary; }

            set { salary = value; }

        }

 

        public override string ToString()

        {

            /*return String.Format("{0} {1} with a payroll of {2}",

      firstName, lastName, salary);*/

 

            //OR

 

            return "" + firstName + " " + lastName + " " + "with a payroll of " + salary + "";

        }

    }

 

    public class Department

    {

        private Employee[] emps;

        private string name;

 

        public Department(Employee[] theEmps, string name)

        {

            emps = theEmps;

            this.name = name;

        }

        public string Name

        {

            get { return name; }

        }

 

        // declaring a nested delegate type that accepts an Employee instance

        public delegate void EmployeeCallback(Employee e);

 

        // This method accepts an EmployeeCallback instance thus

        // providing the Callback mechanism

        public void ProcessEmployees(EmployeeCallback callback)

        {

            foreach (Employee x in emps)

            {

                callback(x);

            }

        }

    }

 

    public class Sys

    {

        private static void UpdatePayroll(Employee y)

        {

            y.Salary *= 1.2m;

 

            Console.WriteLine("The Employee {0} {1}'s salary increased to {2}",

            y.FirstName, y.LastName, y.Salary);

        }

 

        public static void Main()

        {

            Employee emp1 = new Employee("Marina", "Joe", 7000m);

            Employee emp2 = new Employee("Mina", "Nader", 7000m);

            Employee emp3 = new Employee("Johny", "Hany", 9000m);

 

            Employee[] emps = new Employee[3];

            emps[0] = emp1;

            emps[1] = emp2;

            emps[2] = emp3;

 

            Department dep = new Department(emps, "IT");

 

            foreach (Employee z in emps)

            {

                Console.WriteLine(z.ToString());

            }

 

            Console.WriteLine("\nCreating the delegate object");

            // creating the delegate instance

            Department.EmployeeCallback updateCallback =

                    new Department.EmployeeCallback(UpdatePayroll);

 

            Console.WriteLine("calling the method ProcessEmployees()\n");

            dep.ProcessEmployees(updateCallback);

 

            Console.ReadLine();

        }

    }

}

/*

Marina Joe with a payroll of 7000

Mina Nader with a payroll of 7000

Johny Hany with a payroll of 9000

 

Creating the delegate object

calling the method ProcessEmployees()

 

The Employee Marina Joe's salary increased to 8400.0

The Employee Mina Nader's salary increased to 8400.0

The Employee Johny Hany's salary increased to 10800.0

*/


Answers (2)