static void Main(string[] args) { TrafficSignal ts = new TrafficSignal(); TrafficDel deltraffic = new TrafficDel(ts.Yellow); deltraffic(); deltraffic += ts.Green; deltraffic(); deltraffic += ts.Red; deltraffic(); }
static void Main(string[] args) { TrafficDel functionRef; TrafficSignal signal = new TrafficSignal(); functionRef = signal.Yellow; functionRef(); functionRef = signal.Green; functionRef(); functionRef = signal.Red; functionRef(); Console.Read(); }
static void Main(string[] args) { TrafficSignal mySignal = new TrafficSignal(); TrafficDel myTrafficLight = mySignal.Yellow; myTrafficLight(); myTrafficLight = mySignal.Red; myTrafficLight(); myTrafficLight = mySignal.Green; myTrafficLight(); }
static void Main(string[] args) { //TrafficSignal class object TrafficSignal trafficSignal = new TrafficSignal(); //Create and assign the delegate to Red delegate method and then call it TrafficDel signalDelegate = trafficSignal.Red; signalDelegate(); //Assign the delegate to Yellow delegate method and then call it signalDelegate = trafficSignal.Yellow; signalDelegate(); //Assign the delegate to Green delegate method and then call it signalDelegate = trafficSignal.Green; signalDelegate(); }