ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 03/24 델리게이트 연습
    C#/수업내용 2021. 3. 24. 11:08

     

    Program.cs

    using System;
    
    namespace Study07
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Main");
                new App();
            }
        }
    }
    

     

    App.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    
    namespace Study07
    {
        //대리자 선언
        public delegate void DelPrint(string msg);
        public delegate string DelPrintWithLogo(string logo, string msg);
    
        //프린터기
        public class Printer
        {
            public Printer()
            {
    
            }
            public void Print(string msg)
            {
                Console.WriteLine(msg);
            }
            public string PrintWithLogo(string logo, string message)
            {
                return message + "\n" + logo;
            }
        }
        public class App
        {
            //생성자 
            public App()
            {
                Console.WriteLine("App");
                //대리자 초기화
                string message = "동해물과 백두산이...";
                Printer printer = new Printer();
                DelPrint delPrint = new DelPrint(printer.Print);
                delPrint(message);
    
                DelPrint delPrint2 = delegate (string msg)
                {
                    Console.WriteLine("**** 무명메서드 ****");
                    Console.WriteLine(msg);
                };
                //대리자 호출
                delPrint2(message);
    
                //람다식
                DelPrint delPrint3 = (msg) =>
                {
                    Console.WriteLine("**** 람다식 ****");
                    Console.WriteLine(msg);
                };
    
                //대리자 호출
                delPrint3(message);
    
                string logo = @"
    
                                                                                                        
                                                                                                        
                                                           ,..                                          
                                                   ,=-   =@,,~;#;                                       
                                                $@#, @@@$,     @@~  #@=                                 
    #@@@@$*;-  ~*:.                            @                 .** ..#@                               
         ~$@@*~!$@##@@*                     .@@                    . ,.,,#~                             
           .:$@@##*,:$$!#@-              @!@;                     ......*#@                             
                 !@#:*:,;!:@@          @*            .,~--.   .. ....,,,,@@                             
                    .@@--,.~-!@,     .#         .=*!;:~~---~;*!  -.,,.,-,-#@-;=                         
                       -@$   ..:@.   @       ,=!;~~~:::::~-.  .-!,.-..,,,---::;@                        
                          #@,    !@~@      :*::~;!-,... .  -!:- .,!.-,,,--,--::!#                       
                            =#.   .#-    ;*--;!!,*,,-~:-. ~    *: .,~.:,,-~--~~;$:                      
                              #*    ;#.,*~ ~-..*;-,,,!.:.  :-  ,.;, .;,~,-~~~~~:;@                      
                              ,@@.   ,@;.:,; ;.,.--,,~..,,,: .~.  !;..;,,~---~~*@@-                     
                             -@ @:.   .@-  ; .,--:,--~,.... !..~  -;:.--:,-~~-~@@@*                     
                             @ ,$=@.   ,#~ ; !-,,,~~,~,...;.,;  . .**- --:~~~~~~@@#                     
                             @ @-,$@    ;; ~,-;--;!,,~~,;.!,~.., ,::*;..::,~~~~:@@@                     
                            @ ,: :*~#.   @,- .!~!!,,,;;~:..:; ,.,,!. ,; ,-;:~:;:*@~                     
                           @  @- #!!=.   .$~ .,*!!--;~!....-....,. ,  ; .~!~:;$;:;*#@                   
                         @@  ;-  @=.:=    @! .:~~:~::-,.. ;!. *..  ! ,@: @@~;@#;:!!!@                   
                        $.   @  .#:;;@    $*:;;~:~;;;;,;#;*$@=!$#@@##!:@$;$;!:#*;!!!$~                  
                       ,$   #.  =;:,*@    -*--~~;#-;::-$@@:#*!#--~=@:;~@#:!=$~$*;!!**@                  
                       @  ..$   @;-~-@    .=:!.~~@#!$;*;#,=$#$=,#@#!:@#;!::@:$=*;!!**@                  
                      =....@.  .$;::,#    .*. @;@@. #*~..;!..!,--#@~#@##;:::;@=!!!***@                  
                      #*..$~   #;~---:    !, #=@~!  .! * @~..$,*@@#~:;;@@@~~@==!!!@@@@                  
                      $...#    @;,:-@     @  #@-:-@   .-., .,#,,,;@#*@@=~:$$==;;!=@@@@                  
                      @..@    ;;!,-!$     #  $. @##  -@@:,!,#*@@@!;!*!!=~-!;!;;;!$@@@@=*=$==;,          
                     *..@,    @!,!~@     @@    @#**@@@=*#*#*@@@#$*!::;=##$==#@@@#;~--,,.,$@@@$==#@      
                    $* !;    ~;;,!@     *$$#=@#!@;!;=*@@$;-,.~;;~~~:!=$#*@#@$#@:~~-,-,;#@@$,.,~..;!     
                   =,..$     @!,*@     *#;!:::::,:$@=,   .....,-*@@@=#$:@=$$;;@$*$!-=;,-,$@.,@;. $.     
                   @  #     :!*@;     @*!:.. ;*-@=.       ..=@@=!:#=#*:=;*$;;:@@~$~-@-,!@~$.,...#,      
                   =:@.     @@~     .  @*,.,~ @;         =@=;=$@,-:@!~@::$#;;@@$~=--@,=#@@~. .,@*       
                  ! @      ,.   -$ @=@ $*.:..@        -@#$*:-. @,,$$~@@$*;;;;:::;@-=@-,=@@-.*....*@~    
                  @ @.~. .=@@@@$@ !=$~-@:::,=       ~@*;$*.;#@@$.-:~$@~;:@:;;:!:@@;@$,#=~#~*,@#;;:,*$   
                  #@ !:#@@!=!$:;@ ;@*-@;#*.#       @#=@@@=;-,!#=.#--#@#:;@;;@#=:$#=@--,,*@:#   *@@##@#@@
                   @  . ,=:!-,,.@~ .@$!@#$@      ;@=:.  ,$$*$@@!,#--~~~:$@::#=*@=*@@:-=@~ #             
                   @     !-;,.~:@, -#*==!@,         ,-.,=$!~,!#:,=@*~:;~@#;=*!*#=:#@@~    -             
                   @     *-!,,#=,@@ @,@ =,             .!#@$*==**;:*;@;@*#;@*~@#=#@@@                   
                  #.     $~:~@-,@:*= @ #         .,*=:;#@#=;:::##;-,~@!!!~@*;!@@@@@@:                   
                 :~      @:-$* @!!~@~ @$        .;#@$*!=$**;;~,@*!-~,@!!~--;-#@@@@@@                    
                 @       ~;,#  #@@=.@~,,    ,@@#$$!;;;:~-;=*~--#=~~,;-!~-~:~#@@@@@@@                    
                 #        !-:@: ,$@$:@*;    @=$*!!-!!;:;:~=;~-:#;~,:,:~-,-~~@@@@@@@                     
                 =        #:,::=:$:~,-@    @!$*=*~~;!;*;;!:;:**=*-:,--,----@@@@@                        
                 :.        *,,~*,.* ;*=   ;$*:*!!~*!;:!=:-~:$$~:~;,---,,--:@@@@                         
                 .#@-      #: *=   ,=@.   @*~~*!:-!;!=!=;~!=*:!-;--~-~-~-~;:@@!                         
                  $@@     . *- *$  ; #   #*!-~*=~!=!!*==!$$!~!:!:~~~~~-~-:;;*@                          
                    @      , *, !$. #.  .#$$===!;::~*=*$=*:!;*::~:~~~~~~::;!=@.                         
                    ;,      ,.*. .;;#   @$=::::!~~~~!$=!:;*:*-~~~~~-:::;:;;!@@=                         
                    @       .~ *-  =,  -#$::;~;!!==*=!;:*;*;;:::~~-:::::;;!@@@@                         
                    $       ..:,,;,@  ,@$====;==**:;~:=;=*;;;;:~~~~-~;::!;@@@@                          
                   !.       ...~;,~:  ~$*!;!!!!;;;!*!!=*;!;;;;;~::-@@@;!!@@@@~                          
                    @    . ....,,:@. .@$=***!**=*;!*=~*!!!!!;;::::#@@@@#@@@@*                           
                    ;:  -  ....,..$  *$*:~~::;!*=*~!!!;!!*!!;;;:$@@@@@@@@@@$                            
                     @ ;@= ...,-,*- .@!~-~~~~~:;;;!!!!!!!!!!;;;@@@@@@@@@@@=                             
                      @@@@$...,,,@! =#!-~~::;;;;;;!!!!!!!**!;!!@@@@@@;  $*                              
                      .@@@@#,,,,,;..@*;::;;:;;;;;;!!;!!**!!!*!*@@@@@                                    
                         #@@,-,,*@ !#*~~::::;;;;;;;;!!!*!******@@@$                                     
                           @,---@~~=!:~~:::::;;;;;!!!!!***=**==#@@                                      
                           @~-~-#.~$:~~~:::;;;;!;;*#@@#*=*===$@@@@                                      
                           @$--;#!@@@##;;;;;;;;!@@@@@@@====$@@@@@@                                      
                            :@!~-!@@@@@#;;;!!!;#@@@@@@@@=@@@@@@@@                                       
                              *@!@@@@@@@!!;!!!!@@@@@@@@;@@@@@@@.                                        
                               =@@@@@@ *;!!!!**@@@@@     @@@#                                           
                               !@  $#   @@@@@@@@@@@,      ,                                             
                              ;*        .@@@@@@@@@@                                                     
                              @.           ~!$$=;.                                                      
                              !                                                                         
                             =                                                                          
                             ~                                                                          
                                                                                                        
    ";
    
                DelPrintWithLogo delPrint4 = new DelPrintWithLogo(printer.PrintWithLogo);
                string paper = delPrint4(logo, "던파에 오신걸 환영합니다.");
                Console.WriteLine(paper);
    
                //람다식
                DelPrintWithLogo delPrint5 = (logoArg, msg) => string.Format("{0}\n{1}", logoArg, msg);
                string paper2 = delPrint5(logo, "던파에 오신걸 환영합니다.");
                Console.WriteLine(paper2);
            }      
    
        }
    
    }

    'C# > 수업내용' 카테고리의 다른 글

    03/24 SortedList, IComparable 연습  (0) 2021.03.24
    03/24 callback 연습  (0) 2021.03.24
    03/24 Event연습  (0) 2021.03.24
    03/23 수업내용 메모  (0) 2021.03.23
    03/23 List<T>.Find(Predicate<T>) 메서드 연습  (0) 2021.03.23
Designed by Tistory.