예제 #1
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "My Vidoe!"
            };
            var videoEncoder = new VideoEncoder();   // publisher
            var mailService  = new MailService();    // subscriber
            var msgService   = new MessageService(); // subscriber

            videoEncoder.videoEncoded += mailService.OnVideoEncoded;
            videoEncoder.videoEncoded += msgService.OnVideoEncoded;

            videoEncoder.Encode(video);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var video = new Video()
            {
                Title = "bbbbb1"
            };
            var videoEncoder = new VideoEncoder(); //publisher
            var mailService1 = new MailService1(); //subscriber 1
            var mailService2 = new MailService2(); //subscriber 2

            //var mailService3 = new MailService3();//subscriber 3 can be easily added by just adding new class

            videoEncoder.VideoEncoded += mailService1.OnVideoEncoded; // publisher & subscriber signature must match
            videoEncoder.VideoEncoded += mailService2.OnVideoEncoded; // publisher & subscriber signature must match
            videoEncoder.Encode(video);

            Console.WriteLine("Done");
            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            var videoFormatter = new VideoEncoder();

            videoFormatter.VideoEncoded += new EmailService().SendEmail;
            videoFormatter.VideoEncoded += new MessageService().SendText;

            videoFormatter.Encode(new Video()
            {
                Name = "My Video"
            });
            Console.ReadLine();

            //Lambda Expression
            AreaCalculator areaOfCircleCalculater = (r) => 3.14 * r * r;
            double         area = areaOfCircleCalculater(20);

            System.Console.WriteLine($"Area of circle {area}");

            //Func delegate
            Func <int, double> areaOfCircleFunc = (r) => 3.14 * r * r;
            double             areaFunc         = areaOfCircleFunc.Invoke(20);

            System.Console.WriteLine($"Area of circle using Func {area}");

            //Action delegate
            Action <int> areaOfCircleAction = (r) =>
            {
                Console.WriteLine($"Area of circle using Action {3.14 * r * r}");
            };

            areaOfCircleAction.Invoke(20);

            //Predicate delegate
            Predicate <int> isAreaGreaterThanRadius = (r) => r > (3.14 * r * r);
            bool            isAreaGreater           = isAreaGreaterThanRadius.Invoke(20);

            System.Console.WriteLine($"Is Area greater than radius, {isAreaGreater}");
            Console.ReadLine();
        }