Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                Campainha campainha = new Campainha();
                campainha.OnCampainhaTocou += CampainhaTocou1;
                campainha.OnCampainhaTocou += CampainhaTocou2;
                Console.WriteLine("A campainha será tocada.");
                campainha.Tocar("101");

                campainha.OnCampainhaTocou -= CampainhaTocou1;
                Console.WriteLine("A campainha será tocada.");
                campainha.Tocar("202");
            }
            catch (AggregateException e)
            {
                foreach (var exc in e.InnerExceptions)
                {
                    Console.WriteLine(exc.Message);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            Campainha campainha = new Campainha();

            //campainha.Tocar();
            //campainha.OnCampainhaTocou = new Action(() => { });
            campainha.OnCampainhaTocou += CampainhaTocou1;
            campainha.OnCampainhaTocou += CampainhaTocou2;

            campainha.Tocar();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Campainha campainha = new Campainha();

            campainha.OnCampainhaTocou += CampainhaTocou;
            Console.WriteLine("A campainha será tocada.");
            campainha.Tocar();

            campainha.OnCampainhaTocou -= CampainhaTocou;
            Console.WriteLine("A campainha será tocada.");
            campainha.Tocar();

            Console.ReadKey();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            //Campainha campainha = new Campainha();
            //campainha.OnCampainhaTocou += CampainhaTocou1;
            //campainha.OnCampainhaTocou += CampainhaTocou2;

            //Console.WriteLine("Chamando campainha.Tocar()");
            //campainha.Tocar();

            //Console.ReadKey();


            //Campainha campainha = new Campainha();
            //campainha.OnCampainhaTocou += CampainhaTocou1;
            //campainha.OnCampainhaTocou += CampainhaTocou2;
            //Console.WriteLine("Chamando campainha.Tocar()");
            //campainha.Tocar();
            //campainha.OnCampainhaTocou -= CampainhaTocou1;
            //Console.WriteLine("Chamando campainha.Tocar()");
            //campainha.Tocar();
            //Console.ReadKey();

            //Campainha campainha = new Campainha();
            //campainha.OnCampainhaTocou += CampainhaTocou1;
            //campainha.OnCampainhaTocou += CampainhaTocou2;
            //Console.WriteLine($"Chamando campainha.Tocar(202)");
            //campainha.Tocar("202");
            //campainha.OnCampainhaTocou -= CampainhaTocou1;
            //Console.WriteLine($"Chamando campainha.Tocar(104)");
            //campainha.Tocar("104");
            //Console.ReadKey();

            Campainha campainha = new Campainha();

            campainha.OnCampainhaTocou += CampainhaTocou1;
            campainha.OnCampainhaTocou += CampainhaTocou2;
            try
            {
                campainha.Tocar("202");
            }
            catch (AggregateException agg)
            {
                foreach (Exception ex in agg.InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.ReadKey();
        }