Delegate
The following code illustrates a situation where a boss wants to keep track of the work progress of its subordinates:
using System;
namespace BigCompany {
public class Boss
{
public void WorkerPercentageDone(int percentage)
{
Console.WriteLine("I am the boss, and my worker is " + percentage + "% done.");
}
}
public class Worker
{
Boss boss = null;
public Worker(Boss boss)
{
this.boss = boss;
}
public void DoWork()
{
boss.WorkerPercentageDone(20);
boss.WorkerPercentageDone(50);
boss.WorkerPercentageDone(80);
boss.WorkerPercentageDone(100);
}
}
class Program
{
static void Main(string[] args)
{
Boss theBoss = new Boss();
Worker someWorker = new Worker(theBoss);
someWorker.DoWork();
}
}
}
By using an event delegates, change the code above so that another object of type "Manager", that you will write, will also get notified by the worker's progress.
Questions by musclebai answers by musclebai
Showing Answers 1 - 2 of 2 Answers
Related Answered Questions
Related Open Questions
Delegate
using System;
namespace BigCompany {
public class Boss
{
public void WorkerPercentageDone(int percentage)
{
Console.WriteLine("I am the boss, and my worker is " + percentage + "% done.");
}
}
public class Worker
{
Boss boss = null;
public Worker(Boss boss)
{
this.boss = boss;
}
public void DoWork()
{
boss.WorkerPercentageDone(20);
boss.WorkerPercentageDone(50);
boss.WorkerPercentageDone(80);
boss.WorkerPercentageDone(100);
}
}
class Program
{
static void Main(string[] args)
{
Boss theBoss = new Boss();
Worker someWorker = new Worker(theBoss);
someWorker.DoWork();
}
}
}
By using an event delegates, change the code above so that another object of type "Manager", that you will write, will also get notified by the worker's progress.
Profile Answers by musclebai Questions by musclebai
Questions by musclebai answers by musclebai
Related Answered Questions
Related Open Questions