Example #1
0
        static void Main(string[] args)
        {
            // ArrayList arrayList = new ArrayList() { 1, "2" };

            #region List
            //List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };

            //numbers.Add(6);
            //numbers.Add(12);
            //numbers.Remove(3);

            //foreach (var item in numbers)
            //{
            //    Console.WriteLine("From numbers: " + item);
            //}

            //Console.WriteLine(numbers[2]);
            #endregion
            #region Dictionary
            //Dictionary<string, string> sedc =
            //new Dictionary<string, string> { { "Igor", "trainer" }, { "Dejan", "ninja" } };

            //sedc.Add("Veko", "Po Taka");
            //Console.WriteLine(sedc["Igor"]);

            //Dictionary<int, string> people =
            //new Dictionary<int, string> { { 0, "Andrej" }, { 1, "Boban" } };

            //Dictionary<string, string> phonebook = new Dictionary<string, string>
            //{
            //    { "Igor", "389792679" },
            //    { "Gorjan", "389795449" },
            //    { "Dalibor", "389452179" },
            //    { "Voskresija", "389770179" },
            //    { "Kornelija", "389485279" },
            //};
            //Console.Write("Search phonebook by name: ");
            //string query = Console.ReadLine();
            //string result = SearchPhoneBook(phonebook, query);
            //Console.WriteLine($"The number for {query} is {result}");
            #endregion

            #region Queue
            //Queue<int> nums = new Queue<int>();

            //nums.Enqueue(1);
            //nums.Enqueue(2);
            //nums.Enqueue(3);
            //nums.Enqueue(4);
            //Console.WriteLine(nums.Peek());

            //nums.Dequeue();
            //Console.WriteLine(nums.Peek());
            #endregion

            #region Stack
            //Stack<char> chars = new Stack<char>();

            //chars.Push('a');
            //chars.Push('b');
            //chars.Push('c');
            //chars.Push('d');

            //Console.WriteLine(chars.Peek());
            //chars.Pop();
            //Console.WriteLine(chars.Peek());
            #endregion

            #region Linq

            //List<Dog> dogs = new List<Dog>
            //{
            //    new Dog("Barky", 3),
            //    new Dog("Cvarki", 5),
            //    new Dog("Spikey", 2),
            //    new Dog("Laika", 7),
            //    new Dog("Bubic", 12)
            //};

            //List<string> startsWithB = dogs.Where(dog => dog.Name.StartsWith("B")).Select(dog => dog.Name).ToList();

            //List<int> agesOfDogs = dogs.Select(dog => dog.Age).ToList();
            //foreach (int dogage in agesOfDogs)
            //{
            //    Console.WriteLine(dogage);
            //}


            #endregion


            #region musicapp

            List <Person> FansArray = CreateFans();
            List <Song>   Songs     = CreateSongs();

            Person Jerry = FansArray.FirstOrDefault(fan => fan.FirstName == "Jerry");

            Jerry.FavoriteSongs = Songs.Where(song => song.Title.StartsWith("B")).ToList();

            //Jerry.FavoriteSongs = (from song in Songs
            //                       where song.Title.StartsWith("B")
            //                       select song).ToList();
            Jerry.GetFavSongs();
            #endregion
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            List <Person> FansArray = CreateFans();
            List <Song>   Songs     = CreateSongs();

            //"Jerry" task.

            Person Jerry = FansArray.FirstOrDefault(fan => fan.FirstName == "Jerry");

            Jerry.FavoriteSongs = Songs.Where(song => song.Title.StartsWith("B")).ToList();

            Console.WriteLine("Jerry's favorite songs, that start with the letter \"B\":");
            Console.WriteLine();

            Jerry.GetFavSongs();
            Console.WriteLine();

            //"Maria" task.

            Person Maria = FansArray.FirstOrDefault(fan => fan.FirstName == "Maria");

            Maria.FavoriteSongs = Songs.Where(song => ((double)song.Length / 60) > 6.00).ToList();

            Console.WriteLine("Maria's favorite songs, that are longer than 6 minutes:");
            Console.WriteLine();

            Maria.GetFavSongs();
            Console.WriteLine();

            //"Jane" task.

            Person Jane = FansArray.FirstOrDefault(fan => fan.FirstName == "Jane");

            Jane.FavoriteSongs = Songs.Where(song => song.Genre == Genre.Rock).ToList();

            Console.WriteLine("Jane's favorite songs, that are of genre Rock:");
            Console.WriteLine();

            Jane.GetFavSongs();
            Console.WriteLine();

            //"Stefan" task.

            Person Stefan = FansArray.FirstOrDefault(fan => fan.FirstName == "Stefan");

            Stefan.FavoriteSongs = Songs.Where(song => ((double)song.Length / 60) < 3.00).Where(song => song.Genre == Genre.Hip_Hop).ToList();

            Console.WriteLine("Stefan's favorite songs, that are of genre Hip Hop and shorter than 3 minutes:");
            Console.WriteLine();

            Stefan.GetFavSongs();
            Console.WriteLine();

            //Fans that have 4 or more favorite songs.

            Console.WriteLine("All persons from the persons array that have 4 or more favorite songs");
            Console.WriteLine();

            foreach (var fan in FansArray)
            {
                if (fan.FavoriteSongs.Count >= 4)
                {
                    Console.WriteLine(fan.FirstName);
                }
            }

            Console.ReadLine();
        }