Ejemplo n.º 1
0
        public void UseSeveralDelegates()
        {
            var logger       = new Logger();
            var betterLogger = new BetterLogger();

            var write = new WriteMessage(logger.WriteMessage);

            var result = write("Use");

            write += betterLogger.WriteMessage; // The delegate can subscribe to another method

            var betterResult = write("Use");    //Once you subscribed to the new  method, you can use the delegate

            Assert.AreEqual(betterResult, "UseDelegate with Better");
        }
Ejemplo n.º 2
0
        public void UseSeveralDelegates()
        {
            var logger = new Logger();
            var betterLogger = new BetterLogger();

            var write = new WriteMessage(logger.WriteMessage); 

            var result = write("Use");

            write += betterLogger.WriteMessage; // The delegate can subscribe to another method

            var betterResult = write("Use");//Once you subscribed to the new  method, you can use the delegate

            Assert.AreEqual(betterResult, "UseDelegate with Better");
        }