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

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

            Console.ReadLine();
        }
示例#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();
        }
示例#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();
        }
示例#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();
        }
示例#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();
        }
示例#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();
        }
示例#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();
        }
示例#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();
        }
示例#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);
            }
        }
示例#11
0
 static void Main(string[] args) {
     MediaPlayer mp = new MediaPlayer();
     mp.Play();
     mp.GetAllTracks();
     Console.ReadLine();
 }