C#/수업 내용

[C#] Action 람다식 연습문제

JSH1 2021. 9. 7. 14:42
        public App()
        {
            this.LoadDatas(() =>
            {
                Console.WriteLine("loaded all datas...!!!");
            });

        }

        void LoadDatas(Action callback)
        {
            callback();
        }


        public App()
        {
            //물, 우유, 설탕, 소금, 강력분, 이스트, 버터
            string[] ingredient = { "물", "우유", "설탕", "소금", "강력분", "이스트", "버터" };

            /*
             * Cook메서드가 출력하는거...
             *  물, 우유, 설탕, 소금, 강력분, 이스트, 버터
                넣고 반죽을 합니다. 
                오븐에 넣고 기다립니다. 
                빵이 만들어졌습니다.*/

            this.Cook(ingredient, (bread) =>
            {
                Console.WriteLine(bread);       //Bread (인스턴스)
            });
        }

        void Cook(string[] ingredient, Action<Bread> callback)
        {
            for (int i = 0; i < ingredient.Length; i++)
            {
                Console.Write("{0}, ",ingredient[i]);
            }
            Console.WriteLine();
            callback(new Bread());
        }
    class Bread
    {

    }


 

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

[C#] Comparison  (0) 2021.09.07
[C#] Func 람다식 연습문제  (0) 2021.09.07
[C#] delegate callback  (0) 2021.09.06
[C#] Delegate 대리자  (0) 2021.09.06
[C#] try/catch 예외 및 예외 처리  (0) 2021.09.06