如下代码内容是关于C# 委托现实范例的代码,应该是对小伙伴也有用处。
using System;
using System.Collections.Generic;
using System.Text;
namespace Delegate {
public class Heater {
private int temperature;
public void BoilWater() {
for (int i = 0; i <= 100; i++) {
temperature = i;
if (temperature > 95) {
}
}
}
}
}
public class Alarm {
public void MakeAlert(int param) {
Console.WriteLine("Alarm:嘀嘀嘀,水已经 {0} 度了:", param);
}
}
public class Display {
Console.WriteLine("Display:水快烧开了,当前温度:{0}度。", param);
}
}
class Program {
static void Main() {
Heater heater = new Heater();
Alarm alarm = new Alarm();
}
}
}
输出为:Alarm:嘀嘀嘀,水已经96度了:Alarm:嘀嘀嘀,水已经96度了:Display:水快烧开了,当前温度:96度。