<대리자 체인> : 여러개의 메소드를 동시에 참조할 수 있음
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { delegate void ThereIsAsFire(string location); //ThereIsAsFire 대리자 선언 static void Call119(string location)//메소드선언 { Console.WriteLine("Call119"); } static void ShotOut(string location)//메소드선언 { Console.WriteLine("ShotOut"); } static void Escape(string location)//메소드선언 { Console.WriteLine("Escape"); } static void Main(string[] args) { ThereIsAsFire Fire = new ThereIsAsFire(Call119); Fire += new ThereIsAsFire(ShotOut); //+=연산자를 이용하여 체인만들기 Fire += new ThereIsAsFire(Escape); //+=연산자를 이용하여 체인만들기 Fire -= new ThereIsAsFire(ShotOut); //-=를 이용하여 체인 끊기 --> 호출 안됨 Fire("우리집"); } } }
'코딩연습 > C#' 카테고리의 다른 글
[C#]LINQ (0) | 2020.06.12 |
---|---|
[C#]대리자의 이벤트 (0) | 2020.06.12 |
[C#]대리자(delegate) (0) | 2020.06.12 |
[C#]강제로 예외던지기(throw) (0) | 2020.06.12 |
[C#]오라클 연동 (0) | 2020.06.11 |