Example #1
0
        public static void DemoDistinct()
        {
            Console.WriteLine("Full demo list of CHess Players:\n");
            foreach (var player in ChessPlayer.GetDemoList())
            {
                Console.WriteLine(player);
            }

            Console.WriteLine("\nCustom Disctinct\n");

            var discinctByRating = ChessPlayer.GetDemoList().Distinct(new DistinctComparer());

            foreach (var player in discinctByRating)
            {
                Console.WriteLine(player);
            }
            //string str = "Hello, World";

            //Console.WriteLine("\"Hello, World\" contains the following chars:");
            //foreach (var c in str.ToCharArray().Distinct())
            //{
            //    Console.Write(c);
            //}

            //Console.WriteLine("\n");
        }
Example #2
0
        private static void DemoNoYield()
        {
            var players = ChessPlayer.GetDemoList().Filter(c => c.Country == "USA");

            foreach (var player in players)
            {
                Console.WriteLine(player);
            }
        }
Example #3
0
        public static void ToDictionary()
        {
            var players      = ChessPlayer.GetDemoList();
            var chessPlayers = players.ToDictionary(x => x.Id);

            foreach (var player in chessPlayers)
            {
                Console.WriteLine($"Id: {player.Key}. Last Name: {player.Value.LastName}");
            }
        }
Example #4
0
        private static void ElementAtCount()
        {
            var players = ChessPlayer.GetDemoList();

            int  count     = players.Count(p => p.Country == "USA");
            long longCount = players.LongCount();

            ChessPlayer x = players.ElementAt(1);

            Console.WriteLine($"Count: {count} Long Count: {longCount}  Player at Index 1 {x}");
            Console.WriteLine();
        }
        public static void DemoDistinctRating()
        {
            Console.WriteLine("\nFull Demo list of Chess Players:\n");

            foreach (var player in ChessPlayer.GetDemoList())
            {
                Console.WriteLine(player);
            }

            Console.WriteLine("\nCustom Distinct\n");
            var distintByRating = ChessPlayer.GetDemoList().Distinct(new RatingsComparer());

            foreach (var rating in distintByRating)
            {
                Console.WriteLine(rating);
            }
        }
Example #6
0
        public static void ToArrayToList()
        {
            var chessplayers1 = ChessPlayer.GetDemoList().ToList();
            var chessplayers2 = ChessPlayer.GetDemoList().ToArray();

            Console.WriteLine("Players in list");
            foreach (var player in chessplayers1)
            {
                Console.WriteLine($"Player Name: {player.LastName}");
            }

            Console.WriteLine("\nPlayers in array\n");
            foreach (var player in chessplayers2)
            {
                Console.WriteLine($"Player Name: {player.LastName}");
            }
            Console.WriteLine();
        }
Example #7
0
        private static void Projections_with_Select()
        {
            var players   = ChessPlayer.GetDemoList().ToList();
            var ratings   = players.Select(p => p.Rating);
            var lastNames = players.Select(p => p.LastName);
            var FullNames = players.Select(p => $"{p.LastName} {p.FirstName}");

            var anonymousType = players.Select((p, index) => new { Index = index, p.FirstName, p.LastName });

            foreach (var rating in ratings)
            {
                Console.WriteLine(rating);
            }
            Console.WriteLine();
            foreach (var type in anonymousType)
            {
                Console.WriteLine($"{type.FirstName } {type.LastName}");
            }
        }
        public static void AnyAllContains()
        {
            var  players  = ChessPlayer.GetDemoList().ToList();
            bool contains = players.Contains(new ChessPlayer()
            {
                Id        = 6,
                BirthYear = 1993,
                FirstName = "Wesley",
                LastName  = "So",
                Rating    = 2780,
                Country   = "USA"
            }, new PlayerComparer());

            bool any = players.Any(p => p.Country == "FRA");

            bool all = players.All(p => p.Rating > 2500);

            Console.WriteLine($"Contains = {contains}, Any = {any} and All = {all}");
        }
Example #9
0
 private static IEnumerable <ChessPlayer> FilterPlayersByMinumumRating(int minRating)
 {
     return(ChessPlayer.GetDemoList().Where(p => p.Rating >= minRating));
 }