示例#1
0
        static void Main(string[] args)
        {
            var MediaStorageInstance        = new MediaStorage();
            var AudioPlayerInstance         = new AudioPlayer();
            var AudioPlayerDelegateInstance = new MediaStorage.PlayMedia(AudioPlayerInstance.PlayAudioFile);

            MediaStorageInstance.ReportResult(AudioPlayerDelegateInstance);
        }
示例#2
0
        static void Main(string[] args)
        {
            var mediaStorage = new MediaStorage();
            var audioPlayer = new AudioPlayer();
            var videoPlayer = new VideoPlayer();

            var audioDelegate = new MediaStorage.PlayMedia(audioPlayer.PlayAudio);
            var videoDelegate = new MediaStorage.PlayMedia(videoPlayer.PlayVideo);

            mediaStorage.ReportResult(new AudioPlayer().PlayAudio);
            mediaStorage.ReportResult(audioDelegate);
            mediaStorage.ReportResult(videoPlayer.PlayVideo);
        }
示例#3
0
        public void Run()
        {
            MediaStorage myMediaStorage = new MediaStorage();

            AudioPlayer myAudioPlayer = new AudioPlayer();
            VideoPlayer myVideoPlayer = new VideoPlayer();

            MediaStorage.PlayMedia audioPlayerDelegate = new MediaStorage.PlayMedia(myAudioPlayer.PlayAudioFile);
            MediaStorage.PlayMedia videoPlayerDelegate = new MediaStorage.PlayMedia(myVideoPlayer.PlayVideoFile);

            myMediaStorage.ReportResult(audioPlayerDelegate);
            myMediaStorage.ReportResult(videoPlayerDelegate);
        }
            public void Run()
            {
                MediaStorage myMediaStorage = new MediaStorage();

                // instantiate the two media players
                AudioPlayer myAudioPlayer = new AudioPlayer();

                // instantiate the delegates
                MediaStorage.PlayMedia audioPlayerDelegate = new
                                                             MediaStorage.PlayMedia(myAudioPlayer.PlayAudioFile);

                // call the delegates
                myMediaStorage.ReportResult(audioPlayerDelegate);
            }
示例#5
0
        public void Run()
        {
            MediaStorage myMediaStorage = new MediaStorage();

            // instantiate the two media players
            AudioPlayer myAudioPlayer = new AudioPlayer();
            VideoPlayer myVideoPlayer = new VideoPlayer();

            // instantiate the delegates
            MediaStorage.PlayMedia audioPlayerDelegate = new MediaStorage.PlayMedia(myAudioPlayer.PlayAudioFile);
            MediaStorage.PlayMedia videoPlayerDelegate = new MediaStorage.PlayMedia(myVideoPlayer.PlayVideoFile);

            // call the delegates
            myMediaStorage.ReportResult(audioPlayerDelegate);
            myMediaStorage.ReportResult(videoPlayerDelegate);
            
        }
示例#6
0
        //To test the delegate
        public static void run()
        {
            string check = "y";

            while (!(check == "exit" || check == "n"))
            {
                MediaStorage.PlayMedia audioDelegate = new MediaStorage.PlayMedia(AudioFile.playAudio);
                MediaStorage.PlayMedia videoDelegate = new MediaStorage.PlayMedia(VideoFile.playVideo);
                MediaStorage           store         = new MediaStorage();
                store.reportResult(audioDelegate); //non-static field needs object reference
                Console.WriteLine();
                store.reportResult(videoDelegate);
                Console.Write("\r\nEnter any character to continue (Enter 'exit' or 'n' to quit): ");
                check = Console.ReadLine();
                Console.WriteLine();
            }
        }
示例#7
0
        // in Main we use the higher-order function
        public static void Main()
        {
            // instantiate the storage class
            var ms = new MediaStorage();

            // instantiate the player classes
            var aPlayer = new AudioPlayer();
            var vPlayer = new VideoPlayer();

            // instantiate the delegate
            var aDelegate = new MediaStorage.PlayMedia(aPlayer.PlayAudioFile);
            var vDelegate = new MediaStorage.PlayMedia(vPlayer.PlayVideoFile);

            // provide instances to the method using the delegate
            ms.ReportResult(aDelegate);
            ms.ReportResult(vDelegate);
        }
示例#8
0
        static void Main(string[] args)
        {
            // Instatiate the MediaStorage class
            // and each of the media players
            MediaStorage myMediaStorage = new MediaStorage();
            AudioPlayer  myAudioPlayer  = new AudioPlayer();
            VideoPlayer  myVideoPlayer  = new VideoPlayer();

            // Instantiate the delegates
            MediaStorage.PlayMedia audioPlayerDelegate = new MediaStorage.PlayMedia(myAudioPlayer.PlayAudioFile);
            MediaStorage.PlayMedia videoPlayerDelegate = new MediaStorage.PlayMedia(myVideoPlayer.PlayVideoFile);

            // If you uncomment the below line of code you will get a compiler error.
            // We are trying to encapsulate a method that does not match the signature of the delegate.
            //MediaStorage.PlayMedia alternativeDelegate = new MediaStorage.PlayMedia(myAudioPlayer.AlternativePlayer);

            // Delegates are used with the ReportResult() method to see if the media
            // files are valid.
            myMediaStorage.ReportResult(audioPlayerDelegate);
            myMediaStorage.ReportResult(videoPlayerDelegate);

            Console.ReadKey();
        }