Beispiel #1
0
        static void Main(string[] args)
        {
            MediaPlayer myPlayer = new MediaPlayer();
            myPlayer.Play();

            MediaPlayer youPlayer = new MediaPlayer();
            AllTracks yourMusic = youPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with lazy inastantiation ****");
            MediaPlayer mp = new MediaPlayer();

            mp.Play();

            MediaPlayer mp2    = new MediaPlayer();
            AllTracks   tracks = mp2.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Lazy Instantiation * ****\n");
            // No allocation of AllTracks object here!
            var myPlayer = new MediaPlayer();

            myPlayer.Play();
            // Allocation of AllTracks happens when you call GetAllTracks().
            var yourPlayer = new MediaPlayer();
            var yourMusic  = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            //  这里没有分配AkkTracks对象
            MediaPlayer myPlayer = new MediaPlayer();

            myPlayer.Play();

            //  在调用GetAllTracks()时分配AllTracks
            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks   yourMusic  = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #5
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Lazy Instantiation *****\n");

            // No allocation of AllTracks object here!
            MediaPlayer myPlayer = new MediaPlayer();
            myPlayer.Play();

            // Allocation of AllTracks happens when you call GetAllTracks().
            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks yourMusic = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Lazy Instantiation *****\n");

            // This caller does not care about getting all songs,
            // but indirectly created 10,000 objects!
            MediaPlayer myPlayer = new MediaPlayer();

            myPlayer.Play();

            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks   yourMusic  = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            // Никакого размещения объекта AllTracks здесь не происходит
            // из-за ленивого создания объектов
            MediaPlayer myPlayer = new MediaPlayer();

            myPlayer.Play();

            // Размещение объекта AllTracks происходит
            // только в случае вызова метода GetAllTracks()
            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks   yourMusic  = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #8
0
        static void Main()
        {
            Console.WriteLine("***** Fun with Lazy Instatiation *****\n");

            // No allocation of AllTracks object here!
            MediaPlayer myPlayer = new MediaPlayer();

            myPlayer.Play();

            // Allocation of AllTracks happens when you call GetAllTracks().
            MediaPlayer yourPlayer = new MediaPlayer();

            _ = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Lazy Instantiation *****\n");

            //  This caller does not care about getting all songs,
            //  but indirectly created 10,000 objects!
            //  With Lazy<AllTracks>, no allocation of AllTracks object here!
            MediaPlayer myPlayer = new MediaPlayer();

            myPlayer.Play();

            //  Alloctation of AllTracks happens when you call GetAllTracks().
            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks   yourMusic  = yourPlayer.GetAllTracks();

            Console.ReadLine();
        }
Beispiel #10
0
        static void UseLazyObject()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("=> Playback a song");

            MediaPlayer player = new MediaPlayer();

            player.Play();

            MediaPlayer yourPlayer = new MediaPlayer();
            AllTracks   yourMusic  = yourPlayer.GetAllTracks();

            if (yourMusic == null)
            {
                Console.WriteLine("GetAllTracks() return null");
            }
            else
            {
                Console.WriteLine($"Songs size <{yourMusic.Size()}>");
                yourMusic.Choose(0);
                yourMusic.Choose(1);
            }
        }
Beispiel #11
0
 static void Main(string[] args) {
     MediaPlayer mp = new MediaPlayer();
     mp.Play();
     mp.GetAllTracks();
     Console.ReadLine();
 }