static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); var teamsStartWithLA = teams.Where(team => team.Name.StartsWith("La")).ToList(); teamsStartWithLA.ForEach(team => Console.WriteLine(team.Name)); var teamsPleyingInSteplesCenter = teams.Where(team => team.Arena == "Staples Center") .Select(team => team.Name).ToList(); teamsPleyingInSteplesCenter.ForEach(team => Console.WriteLine(team)); var allCoaches = teams.Select(team => team.Coach).ToList(); allCoaches.ForEach(a => Console.WriteLine(a.FullName)); var allOldestAndNamesCoaches = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName).ToList(); allOldestAndNamesCoaches.ForEach(a => Console.WriteLine(a)); var GroupTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); var allPlayer = new List <Player> (); teams.ForEach(team => allPlayer.AddRange(team.Players)); allPlayer.ForEach(pley => Console.WriteLine(pley.FullName)); var pleyarWithMostPtsPerGame = allPlayer.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).FirstOrDefault(); Console.WriteLine(pleyarWithMostPtsPerGame); Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); foreach (var team in teams) { Console.WriteLine(team.Name); } //1-Find all Teams with names starting with LA var teamsStartingWithLa = teams.Where(team => team.Name.StartsWith("LA")).ToList(); // teamsStartingWithLa.ForEach(team => Console.WriteLine(team.Name)); //2-Find all team Names which are playint in Staples Center var teamsPlayingInSteplaesCenter = teams .Where(team => team.Arena == "Staples Center") //moze i team.Arena.Equals("Staples Center") .Select(team => team.Name).ToList(); teamsPlayingInSteplaesCenter.ForEach(team => Console.WriteLine(team)); //3-Find all teams coaches var allCoaches = teams. Select(team => team.Coach).ToList(); allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); //Find 3 oldest coaches Names and age var oldest3CoachesNameAndAge = allCoaches. OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); oldest3CoachesNameAndAge.ForEach(trainerName => Console.WriteLine(trainerName)); //Group all teams by their arenas var groupTeams = teams. GroupBy(team => team.Arena).ToList(); //Console.ForegroundColor = ConsoleColor.Red; //foreach (var group in groupTeams) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"{team.Name}"); // } //} //Find all players var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); allPlayers.ForEach(player => Console.WriteLine(player.FullName)); // dali xznaci deka sekogas koga ima nesto // sto treba da zememe od klasa vo klasa // treba da si pravime prazna lista kako sega // ako sakame od lista u klasa valjda //Find player with best avgPointsPerGame var Avg = allPlayers .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); // HOMEWORK // Find all coaches NAMES with Age > 50 var CoachesNameBiggerThanFifthy = teams. Where(team => team.Coach.Age > 50).ToList(); Console.ForegroundColor = ConsoleColor.Blue; CoachesNameBiggerThanFifthy.ForEach(coach => Console.WriteLine(coach.Name)); // Order players by AGE - DESC var playersByAge = allPlayers. OrderByDescending(player => player.Age).ToList(); Console.ForegroundColor = ConsoleColor.White; playersByAge.ForEach(player => Console.WriteLine(player.Age)); // Find player with highest RebPerGame var HighestPlayer = allPlayers. OrderByDescending(player => player.PlayerStatistic["RebPerGame"]).ToList(); Console.ForegroundColor = ConsoleColor.Green; HighestPlayer.ForEach(player => Console.WriteLine(player.FullName)); // Find all players with PtsPerGame > 20 var PLayerPts = allPlayers. Where(player => player.PlayerStatistic["PtsPerGame"] > 20.0f).ToList(); Console.ForegroundColor = ConsoleColor.Yellow; PLayerPts.ForEach(player => Console.WriteLine(player.FullName)); // Find all players NAMES older then 30 years var PlayerNameOlder = allPlayers. Where(player => player.Age > 30) .Select(player => player.FullName).ToList(); Console.ForegroundColor = ConsoleColor.Red; PlayerNameOlder.ForEach(player => Console.WriteLine(player)); // Group players by age var groupTeam = allPlayers. GroupBy(player => player.Age).ToList(); Console.ForegroundColor = ConsoleColor.White; foreach (var group in groupTeam) { Console.WriteLine($"{group.Key }"); foreach (var player in group) { Console.WriteLine($"{player.FullName}"); } } // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var PrsNamesPlayer = allPlayers. Where(player => player.PlayerStatistic["PtsPerGame"] > 7.0f) .Select(player => player.FullName).ToList(); Console.ForegroundColor = ConsoleColor.Red; PrsNamesPlayer.ForEach(player => Console.WriteLine(player)); // Find first 3 players with highest PtsPerGame var HighestPlayer1 = allPlayers. OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Select(player => player.FullName).Take(3).ToList(); Console.ForegroundColor = ConsoleColor.Green; HighestPlayer1.ForEach(player => Console.WriteLine(player)); // Find the team which has the player with highest PtsPerGame var playerPts = allPlayers. OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).FirstOrDefault(); var BestPlayer = teams.SingleOrDefault(team => team.Players.Contains(playerPts)); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(BestPlayer.Name); //I dont have other idea // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var FourPlayers = allPlayers .OrderBy(player => player.PlayerStatistic["RebPerGame"]).TakeLast(4) .OrderBy(player => player.PlayerStatistic["PtsPerGame"]).ToList(); //fourPhighestRebPerGame.ForEach(player => Console.WriteLine(player.FullName)); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); // teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team NAMES which are playing in "Staples Center" var teamsPlayingInStaplesCenter = teams.Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); // teamsPlayingInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); // allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches NAMES var oldest3CoahcesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); // oldest3CoahcesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupedTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------{team.Name}"); // } //} // Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); // HOMEWORK // Find all coaches NAMES with Age > 50 // Order players by AGE - DESC // Find player with highest RebPerGame // Find all players with PtsPerGame > 20 // Find all players NAMES older then 30 years // Group players by age // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 // Find first 3 players with highest PtsPerGame // Find the team which has the player with highest PtsPerGame // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); // teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team NAMES which are playing in "Staples Center" var teamsPlayingInStaplesCenter = teams.Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); // teamsPlayingInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); // allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches NAMES var oldest3CoahcesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); // oldest3CoahcesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupedTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------{team.Name}"); // } //} // Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); // HOMEWORK //1 Find all coaches NAMES with Age > 50 var oldCoaches = allCoaches.Where(coach => coach.Age > 50).Select(coach => coach.FullName).ToList(); Console.WriteLine("All coaches NAMES with Age > 50:"); oldCoaches.ForEach(coach => Console.WriteLine(coach)); //2 Order players by AGE - DESC var playersByAGe = allPlayers.OrderByDescending(player => player.Age).Select(player => new { player.FullName, player.Age }).ToList(); Console.WriteLine("\n\nOrder players by AGE - DESC"); playersByAGe.ForEach(player => Console.WriteLine(player)); //3 Find player with highest RebPerGame var HighestRPBPlayer = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]).Take(1).ToList(); Console.WriteLine("\n\nPlayer with highest RebPerGame:"); HighestRPBPlayer.ForEach(player => Console.WriteLine(player.FullName)); //4 Find all players with PtsPerGame > 20 var playerWithPPG = allPlayers.Where(player => player.PlayerStatistic["PtsPerGame"] > 20).Select(player => player.FullName).ToList(); Console.WriteLine("\n\nAll players with PtsPerGame > 20"); playerWithPPG.ForEach(player => Console.WriteLine(player)); //5 Find all players NAMES older then 30 years var olderPlayers = allPlayers.Where(player => player.Age > 30).Select(player => player.FullName).ToList(); Console.WriteLine("\n\nAll players NAMES older then 30 years"); olderPlayers.ForEach(player => Console.WriteLine(player)); //6 Group players by age var groupedPlayersByAge = allPlayers.OrderBy(player => player.Age).GroupBy(player => player.Age).ToList(); Console.WriteLine("\n\nGrouped players by age:"); foreach (var group in groupedPlayersByAge) { Console.WriteLine($"{group.Key}"); foreach (var player in group) { Console.WriteLine($"-------------{player.FullName}"); } } //7 Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playersWithALotOfRPG = allPlayers.Where(player => player.PlayerStatistic["RebPerGame"] > 7.0).OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .Select(player => new { player.FullName, player.PlayerStatistic }).ToList(); Console.WriteLine("\n\nAll players NAMES and PtsPerGame if have RebPerGame > 7.0"); playersWithALotOfRPG.ForEach(player => Console.WriteLine($"{player.FullName}, PtsPerGame: {player.PlayerStatistic["PtsPerGame"]}")); //8 Find first 3 players with highest PtsPerGame var highestPPGPlayers = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).Take(3).ToList(); Console.WriteLine("\n\nFirst 3 players with highest PtsPerGame"); highestPPGPlayers.ForEach(player => Console.WriteLine(player.FullName)); //9 Find the team which has the player with highest PtsPerGame var highestPPGPlayer = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).FirstOrDefault(); var teamWithHighestPlayer = teams.FirstOrDefault(team => team.Players.Contains(highestPPGPlayer)); Console.WriteLine("\n\n" + teamWithHighestPlayer.Name); //10 Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var finalPlayers = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4).OrderBy(player => player.PlayerStatistic["PtsPerGame"]).ToList(); finalPlayers.ForEach(player => Console.WriteLine($"{ player.FullName} PtsPerGame: {player.PlayerStatistic["PtsPerGame"]}")); Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); // teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team NAMES which are playing in "Staples Center" var teamsPlayingInStaplesCenter = teams.Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); // teamsPlayingInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); // allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches NAMES var oldest3CoahcesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); // oldest3CoahcesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupedTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------{team.Name}"); // } //} // Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); // HOMEWORK // Find all coaches NAMES with Age > 50 var coachesOverFifty = teams. Where(team => team.Coach.Age > 50).ToList(); //coachesOverFifty.ForEach(coach => Console.WriteLine(coach.Coach.FullName)); // Order players by AGE - DESC var playersSortedByAge = allPlayers. OrderByDescending(player => player.Age). ToList(); //foreach (var player in playersSortedByAge) //{ // Console.WriteLine($"{player.FullName} : {player.Age}"); //} // Find player with highest RebPerGame var playerWithMostReboundsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostReboundsPerGame.FullName); // Find all players with PtsPerGame > 20 var playersWithMoreThanTwentyPPG = allPlayers. FindAll(player => player.PlayerStatistic["PtsPerGame"] > 20). Select(player => player); //foreach (var player in playersWithMoreThanTwentyPPG) //{ // Console.WriteLine($"{player.FullName} : {player.PlayerStatistic["PtsPerGame"] }"); //} // Find all players NAMES older then 30 years var allPlayersNamesOlderThirty = allPlayers. Where(player => player.Age > 30). Select(player => player.FullName). ToList(); //allPlayersNamesOlderThirty.ForEach(player => Console.WriteLine(player)); // Group players by age var groupPlayersAge = allPlayers. GroupBy(player => player.Age). ToList(); //foreach (var player in groupPlayersAge) //{ // Console.WriteLine(player.Key); //} // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playerNamesWithSevenReboundsOrMore = allPlayers. Where(player => player.PlayerStatistic["RebPerGame"] >= 7.0). Select(player => new { Name = player.FullName, Points = player.PlayerStatistic["PtsPerGame"], Rebounds = player.PlayerStatistic["RebPerGame"] }) ; //foreach (var player in playerNamesWithSevenReboundsOrMore) //{ // Console.WriteLine(player); //} // Find first 3 players with highest PtsPerGame var firstThreeScorers = allPlayers. OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).Take(3).ToList(); //firstThreeScorers.ForEach(player => Console.WriteLine //($"{player.FullName}: {player.PlayerStatistic["PtsPerGame"]}")); // Find the team which has the player with highest PtsPerGame var teamHighestScorer = teams.SingleOrDefault(team => team.Players.Contains(playerWithMostPtsPerGame)); //Console.WriteLine(teamHighestScorer.Name); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var topFourRebounders = allPlayers. OrderByDescending(player => player.PlayerStatistic["RebPerGame"]). Take(4) .ToList(). OrderBy(player => player.PlayerStatistic["PtsPerGame"]); foreach (var player in topFourRebounders) { Console.WriteLine($"{player.FullName}, Points: {player.PlayerStatistic["PtsPerGame"]} ,Rebounds: {player.PlayerStatistic["RebPerGame"]} "); } }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // 1. Find all TEAMS with name starting with 'LA' var teamsStartingWithLA = teams .Where(team => team.Name.StartsWith("LA")) .ToList(); teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); Console.WriteLine("-----------------------------"); // 2. Find all team NAMES which are playing in "Staples Center" var teamsPlayingInSC = teams .Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name) .ToList(); teamsPlayingInSC.ForEach(name => Console.WriteLine(name)); Console.WriteLine("-----------------------------"); // 3. Find all teams coaches var allCoaches = teams .Select(team => team.Coach) .ToList(); allCoaches.ForEach(coachName => Console.WriteLine(coachName.FullName)); Console.WriteLine("-----------------------------"); // 4. Find 3 oldest coaches NAMES var threeOldestCoaches = allCoaches .OrderByDescending(team => team.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); threeOldestCoaches.ForEach(coach => Console.WriteLine(coach)); Console.WriteLine("-----------------------------"); // 5. Group all teams by their Arenas var groupTeamsByArenas = teams .GroupBy(team => team.Arena) .ToList(); foreach (var arena in groupTeamsByArenas) { Console.WriteLine(arena.Key); foreach (var team in arena) { Console.WriteLine($"***{team.Name}"); } } Console.WriteLine("-----------------------------"); // 6. Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); allPlayers.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("-----------------------------"); // 7. Find player with best avgPtsPerGame var playeraWithMaxRangPoints = allPlayers .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Select(player => player.FullName) .FirstOrDefault(); Console.WriteLine(playeraWithMaxRangPoints); Console.WriteLine("-----------------------------"); // HOMEWORK Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("HOMEWORK:"); Console.ResetColor(); // 8. Find all coaches NAMES with Age > 50 var coachesOver50 = allCoaches .Where(coach => coach.Age > 50) .Select(coach => coach.FullName) .ToList(); coachesOver50.ForEach(name => Console.WriteLine(name)); Console.WriteLine("-----------------------------"); // 9. Order players by AGE - DESC var playersByAge = allPlayers .OrderByDescending(player => player.Age) .ToList(); playersByAge.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("-----------------------------"); // 10. Find player with highest RebPerGame var playerWithHigherRebPerGame = allPlayers .OrderByDescending(team => team.PlayerStatistic["RebPerGame"]) .FirstOrDefault(); Console.WriteLine(playerWithHigherRebPerGame.FullName); Console.WriteLine("-----------------------------"); // 11. Find all players with PtsPerGame > 20 var playersWithPtsPerGameOver20 = allPlayers .Where(team => team.PlayerStatistic["PtsPerGame"] > 20) .ToList(); playersWithPtsPerGameOver20.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("-----------------------------"); // 12. Find all players NAMES older then 30 years var playersOver30 = allPlayers .Where(player => player.Age > 30) .Select(player => player.FullName) .ToList(); playersOver30.ForEach(player => Console.WriteLine(player)); Console.WriteLine("-----------------------------"); // 13. Group players by age var groupedPlayersByAge = allPlayers .GroupBy(player => player.Age) .ToList(); foreach (var age in groupedPlayersByAge) { Console.WriteLine($"Age: {age.Key}"); foreach (var player in age) { Console.WriteLine($"***Player: {player.FullName}"); } } Console.WriteLine("-----------------------------"); // 14. Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playersWithRebPerGameOver7 = allPlayers .Where(team => team.PlayerStatistic["RebPerGame"] > 7.0) .Select(player => new { player.FullName, player.PlayerStatistic }) .ToList(); playersWithRebPerGameOver7.ForEach(player => Console.WriteLine($"Name: {player.FullName}, PtsPerGame: {player.PlayerStatistic["PtsPerGame"]}")); Console.WriteLine("-----------------------------"); // 15. Find first 3 players with highest PtsPerGame var playersWithHighestPts = allPlayers .OrderByDescending(team => team.PlayerStatistic["PtsPerGame"]) .Take(3) .ToList(); playersWithHighestPts.ForEach(player => Console.WriteLine($"Name: {player.FullName}, PtsPerGame: {player.PlayerStatistic["PtsPerGame"]}")); Console.WriteLine("-----------------------------"); // 16. Find the team which has the player with highest PtsPerGame var playerWithHighestPtsPerGame = playersWithHighestPts.FirstOrDefault(); var teamWithPlayerWithHighestPtsPerGame = teams .FirstOrDefault(team => team.Players.Contains(playerWithHighestPtsPerGame)); Console.WriteLine($"Team: {teamWithPlayerWithHighestPtsPerGame.Name}, Player: {playerWithHighestPtsPerGame.FullName}"); Console.WriteLine("-----------------------------"); // 17. Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var playersWithHighestRebPerGame = allPlayers .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4) .OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); playersWithHighestRebPerGame.ForEach(players => Console.WriteLine(players.FullName)); Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); #region Class 13 LINQ // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); //teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team NAMES which are playing in "Staples Center" var teamsPlayingInStaplesCenter = teams.Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); //teamsPlayingInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); //allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches NAMES var oldest3CoahcesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); //oldest3CoahcesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupedTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------{team.Name}"); // } //} // Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); #endregion #region HOMEWORK Class 13 LINQ Console.ForegroundColor = ConsoleColor.DarkGreen; // Find all coaches NAMES with Age > 50 var allCoachesOver50 = teams.Where(team => team.Coach.Age > 50).Select(team => team.Coach.FullName).ToList(); //allCoachesOver50.ForEach(coach => Console.WriteLine(coach)); // Order players by AGE - DESC var allPlayers2 = new List <Player>(); teams.ForEach(team => allPlayers2.AddRange(team.Players)); var PlayersByAgeDESC = allPlayers2.OrderByDescending(player => player.Age).ToList(); //PlayersByAgeDESC.ForEach(player => Console.WriteLine(player.FullName)); // Find player with highest RebPerGame var highestRebPerGame = allPlayers2.OrderBy(player => player.PlayerStatistic["RebPerGame"]).LastOrDefault(); //Console.WriteLine(highestRebPerGame.FullName); // Find all players with PtsPerGame > 20 var PlayersOver20pts = allPlayers2.Where(player => player.PlayerStatistic["PtsPerGame"] > 20.0f) .ToList(); //PlayersOver20pts.ForEach(player => Console.WriteLine(player.FullName)); // Find all players NAMES older then 30 years var PlayersOver30Years = allPlayers2.Where(player => player.Age > 30).Select(plyer => plyer.FullName).ToList(); //PlayersOver30Years.ForEach(player => Console.WriteLine(player)); // Group players by age var GroupOfPlayers = allPlayers2.GroupBy(player => player.Age).ToList(); //foreach (var AgeOfPlayer in GroupOfPlayers) //{ // Console.WriteLine(AgeOfPlayer.Key); // foreach (var player in AgeOfPlayer) // { // Console.WriteLine($"------------{player.FullName}"); // } // Console.WriteLine("__________________________________"); //} // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playersOver7Reb = allPlayers2.Where(player => player.PlayerStatistic["RebPerGame"] > 7.0f) .Select(player => new { Name = player.FullName, Points = player.PlayerStatistic["PtsPerGame"] }) .ToList(); //playersOver7Reb.ForEach(anonymous => Console.WriteLine(anonymous)); // Find first 3 players with highest PtsPerGame var threePHighestPtsPerGame = allPlayers2.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Take(3).ToList(); //threePHighestPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); // Find the team which has the player with highest PtsPerGame var playerWithHighestPPG = allPlayers2.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); var teamOfTheBestPlayer = teams.SingleOrDefault(team => team.Players.Contains(playerWithHighestPPG)); //Console.WriteLine(teamOfTheBestPlayer.Name); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var fourPhighestRebPerGame = allPlayers2.OrderBy(player => player.PlayerStatistic["RebPerGame"]) .TakeLast(4).OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); //fourPhighestRebPerGame.ForEach(player => Console.WriteLine(player.FullName)); #endregion Console.ReadLine(); }
static void Main(string[] args) { #region Exercises LINQ var teams = TeamsDataBase.GetAllTeams(); // 1. Find all TEAMS with names starting with 'LA' List <Team> laTeams = teams.Where(team => team.Name.StartsWith("LA")).ToList(); laTeams.ForEach(team => Console.WriteLine(team.Name)); Console.WriteLine("=================================="); // 2. Find all team NAMES which are playing in "Staples Center" List <string> staplesCenterTeams = teams .Where(team => team.Arena == "Staples Center") .Select(team => team.Name) .ToList(); List <string> staplesCenterTeamsSecondWay = teams .Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name) .ToList(); staplesCenterTeams.ForEach(team => Console.WriteLine("Staples Center teams first way: " + team)); Console.WriteLine("=================================="); staplesCenterTeamsSecondWay.ForEach(team => Console.WriteLine("Staples Center teams second way: " + team)); Console.WriteLine("=================================="); // 3. Find all team coaches List <Coach> allTeamCoaches = teams.Select(team => team.Coach).ToList(); allTeamCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); Console.WriteLine("=================================="); // 4. Find the 3 oldest coaches NAMES List <string> oldestThreeCoaches = allTeamCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); oldestThreeCoaches.ForEach(name => Console.WriteLine("Oldest coaches " + name)); Console.WriteLine("=================================="); // 4.Extended Display the oldest 3 coaches in the following format => Name: Gregg | Age: 50 var oldestThreeCoachesNameAndAge = allTeamCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => new { FullName = coach.FullName, Age = coach.Age }) .ToList(); oldestThreeCoachesNameAndAge.ForEach(coach => Console.WriteLine($"Name: {coach.FullName} | Age: {coach.Age}")); Console.WriteLine("=================================="); // 5. Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(x => x.Arena).ToList(); foreach (var group in groupedTeamsByArenas) { Console.WriteLine("Arena: " + group.Key); Console.WriteLine("Teams: "); foreach (var team in group) { Console.WriteLine(team.Name); } } Console.WriteLine("=================================="); // 6. Find all players and extraxt them in one list List <Player> allPlayers = new List <Player>(); // One way: more complex foreach (Team team in teams) { foreach (Player player in team.Players) { allPlayers.Add(player); } } // Better way: in one line only teams.ForEach(team => allPlayers.AddRange(team.Players)); allPlayers.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("=================================="); // 7. Group all players by team // Team: LA Lakers // Players: Lebron James, Dwight Howard, Antony Davies var playerGroupedByTeam = teams.GroupBy(x => x.Players).ToList(); foreach (var item in playerGroupedByTeam) { Console.WriteLine("Team: " + item.Last().Name); Console.WriteLine("Players: "); foreach (var player in item.Key) { Console.WriteLine(player.FullName); } } Console.WriteLine("=================================="); // 8. Find player with best avgPtsPerGame Player bestPlayer = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); // Using Max() float maxPtsPerGame = allPlayers.Max(x => x.PlayerStatistic["PtsPerGame"]); Player best = allPlayers .Where(player => player.PlayerStatistic["PtsPerGame"] == maxPtsPerGame) .FirstOrDefault(); Console.WriteLine($"{bestPlayer.FullName} | PtsPerGame: {bestPlayer.PlayerStatistic["PtsPerGame"]}"); Console.WriteLine("================================================="); // 10. Find ALL players that have PtsPerGame > 20 List <Player> aboveTwentyPoints = allPlayers .Where(x => x.PlayerStatistic["PtsPerGame"] > 20) .OrderBy(x => x.PlayerStatistic["PtsPerGame"]) .ToList(); aboveTwentyPoints.ForEach(player => Console.WriteLine(player.PlayerStatistic["PtsPerGame"])); #endregion #region Something new // ArrayList - Non generic collection in C# Console.WriteLine("=========================== Array list example ==================================="); ArrayList array = new ArrayList() { "Martin Panovski", 1, false, true, 21.5f, }; foreach (var item in array) { Console.WriteLine(item); } Console.WriteLine("=================================="); // Any() & All() // 9. Find if there is a player that has > 35 years bool olderThanThirtyFive = allPlayers.Any(player => player.Age >= 35); if (allPlayers.Any(player => player.Age >= 35)) { Console.WriteLine($"There is a player that is older than 35 years."); } else { Console.WriteLine("No player older that 35 years found."); } Console.WriteLine(olderThanThirtyFive); if (allPlayers.All(x => x.Age >= 20 && x.Age <= 35)) { Console.WriteLine("All players satisfied the condition!"); } else { Console.WriteLine("Fail."); } #endregion Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); //teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); //Find all team NAMES playing in Staples Center var allTeamsNameStaplesCenter = teams.Where(team => team.Arena.Contains("Staples Center")).ToList(); //allTeamsNameStaplesCenter.ForEach(team => Console.WriteLine(team.Name)); var allTeamsNameStaplesCenter1 = teams.Where(team => team.Arena == "Staples Center").Select(team => team.Name).ToList(); //allTeamsNameStaplesCenter1.ForEach(team => Console.WriteLine(team)); var allCoaches = teams.Select(team => team.Coach).ToList(); //allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); var oldest3CoachesNamesAndAge = allCoaches.OrderByDescending(coach => coach.Age) .Take(3).Select(coach => coach.FullName).ToList(); //oldest3CoachesNamesAndAge.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"------------- {team.Name}"); // } //} // Find all players in one List var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); // Find a Player With Highest PPG //var bestPtsPerGame = allPlayers.Max(player => player.PlayerStatistic); //Console.WriteLine(bestPtsPerGame.Keys); var BestPPG = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).ToList()[0]; // Moze i FirstOrDefault(); //Console.WriteLine(BestPPG.FullName); //BestPPG.ForEach(player => Console.WriteLine(player.FullName)); //Console.WriteLine(BestPPG.FullName); // HOMEWORK HOMEWORK HOMEWORK HOMEWORK HOMEWORK // Find all coaches NAMES with Age > 50 var coachesNamesAbove50 = allCoaches.Where (coach => coach.Age > 50) .ToList(); //coachesNamesAbove50.ForEach(coach => Console.WriteLine(coach.FullName)); // Order players by AGE - DESC var allPlayersByAge = allPlayers.OrderByDescending (player => player.Age) .ToList(); //allPlayersByAge.ForEach(player => Console.WriteLine(player.FullName)); // Find player with highest RebPerGame var bestRPG = allPlayers.OrderByDescending (player => player.PlayerStatistic["RebPerGame"]) .ToList()[0]; //Console.WriteLine(bestRPG.FullName); // Find all players with PtsPerGame > 20 var ptsPGAbove20 = allPlayers.Where (player => player.PlayerStatistic["PtsPerGame"] > 20) .ToList(); //ptsPGAbove20.ForEach(player => Console.WriteLine(player.FullName)); // Find all players NAMES older then 30 years var playersOlderThan30 = allPlayers.Where (player => player.Age > 30) .ToList(); //playersOlderThan30.ForEach(player => Console.WriteLine(player.FullName)); // Group players by age var groupPlayersByAge = allPlayers.GroupBy(player => player.Age).ToList(); foreach (var group in groupPlayersByAge) { Console.WriteLine($"{group.Key}"); foreach (var player in group) { Console.WriteLine($"------------- {player.FullName}"); } } // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playersWithRPG7OrBigger = allPlayers.Where (player => player.PlayerStatistic["RebPerGame"] > 7) .ToList(); //playersWithRPG7OrBigger.ForEach(player => Console.WriteLine(player.FullName)); //playersWithRPG7OrBigger.ForEach(player => Console.WriteLine(player.PlayerStatistic["PtsPerGame"])); // Find first 3 players with highest PtsPerGame var playersWithMostPPG = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Take(3).Select(player => player.FullName) .ToList(); //playersWithMostPPG.ForEach(player => Console.WriteLine(player)); // Find the team which has the player with highest PtsPerGame var teamWithBestPPGPlayer = teams.First (team => team.Players.Contains(BestPPG)); // Console.WriteLine(teamWithBestPPGPlayer.Name); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var playerswithBestRPG1 = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4).OrderBy (player => player.PlayerStatistic["PtsPerGame"]) .ToList(); //playerswithBestRPG1.ForEach(player => Console.WriteLine(player.FullName)); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all TEAMS with names starting with LA var teamsStartingWithLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); // teamsStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team NAMES which are playing in "Staples Center" var teamsPlayingInStaplesCenter = teams.Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); // teamsPlayingInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); // allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches NAMES var oldest3CoahcesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); // oldest3CoahcesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupedTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------{team.Name}"); // } //} // Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); //Console.WriteLine(playerWithMostPtsPerGame.FullName); //_________________________________________HOMEWORK________________________________________ // ***** Find all coaches NAMES with Age > 50 var allCoachesName50 = allCoaches .Where(coach => coach.Age > 50) .Select(coach => coach.FullName) .ToList(); // allCoachesName50.ForEach(coach => Console.WriteLine(coach)); // ***** Order players by AGE - DESC var orderPlayersByAge = allPlayers .OrderByDescending(player => player.Age) .Select(player => new { player.FullName, player.Age }) .ToList(); // orderPlayersByAge.ForEach(player => Console.WriteLine(player)); // ***** Find player with highest RebPerGame ***** var playerHighestRebPerGame = allPlayers .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(1) .ToList(); // playerHighestRebPerGame.ForEach(player => Console.WriteLine(player.FullName)); // ***** Find all players with PtsPerGame > 20 ***** var allplayerHighestRebPerGame = allPlayers .OrderByDescending(player => player.PlayerStatistic["RebPerGame"] > 20) .ToList(); // allplayerHighestRebPerGame.ForEach(player => Console.WriteLine(player.FullName)); // ***** Find all players NAMES older then 30 years ***** var playersNameOlder30 = allPlayers .Where(player => player.Age > 30) .ToList(); // playersNameOlder30.ForEach(player => Console.WriteLine(player.FullName)); // ***** Group players by age ***** var groupedPlayersByAge = allPlayers .OrderBy(player => player.Age) .GroupBy(player => player.Age) .ToList(); foreach (var group in groupedPlayersByAge) { foreach (var player in group) { // Console.WriteLine($"Name = {player.FullName}. Age = {group.Key}"); } } // ***** Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 ***** var namesPtsPerGameRebPerGame7 = allPlayers .Where(player => player.PlayerStatistic["RebPerGame"] > 7) .OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); // namesPtsPerGameRebPerGame7.ForEach(player => Console.WriteLine($"{player.FullName}____{player.PlayerStatistic["PtsPerGame"]}")); // ***** Find first 3 players with highest PtsPerGame ***** var first3PlayersPtsPerGame = allPlayers .OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .Take(3) .ToList(); // first3PlayersPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); // ***** Find the team which has the player with highest PtsPerGame ***** (Ne mi e jasna) //var teamWhichPlayerHigPTsPerGame = teams....... // ***** Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC ***** var first4HighestRebPtsPerGame = allPlayers .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4) .OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); // first4HighestRebPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); #region od cas ////Find all TEAMS with names starting with LA ////Find all team NAMES which are playing in "Staples Center" ////--------------------------------------------------------- //var teamNamesPlayingInStaplesCenter = teams //ili so == // .Where(team => team.Arena.Equals("Staples Center")) // .Select(team => team.Name) // .ToList(); ////teamNamesPlayingInStaplesCenter.ForEach(teamName => Console.WriteLine(teamName)); //Console.WriteLine("--------------------------------------------------------------"); ////Find all teams coaches ////---------------------- //var allCoaches = teams.Select(team => team.Coach) // .ToList(); ////allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); //Console.WriteLine("--------------------------------------------------------------"); ////Find 3 oldest coaches NAMES and AGE //var threeOldestcoachesNamesAndAge = allCoaches // .OrderByDescending(coach => coach.Age) // .Take(3) // .Select(coach => coach.FullName) // .ToList(); ////threeOldestcoachesNamesAndAge.ForEach(trainerName => Console.WriteLine(trainerName)); //Console.WriteLine("---------------------------------------------------------------"); //Group all teams by their arenas //------------------------------------------------------------------ //var groupTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); //foreach (var group in groupTeamsByArenas) //{ // Console.WriteLine($"{group.Key}"); // foreach (var team in group) // { // Console.WriteLine($"-------------------------------{team.Name}"); // } //} //Console.WriteLine("-----------------------------------------------------------------"); //Find all players //------------------------------ //bez LINQ, sampo so using System.Collections.Generic bez using System.Linq; //var allPlayers = new List<Player>(); //teams.ForEach(team => allPlayers.AddRange(team.Players)); //allPlayers.ForEach(player => Console.WriteLine(player.FullName)); //votr nacin so LINQ, pokomplicirano, so using System.Linq; //var allPlayers1 = teams.Select(team => team.Players).ToList(); //foreach (var players in allPlayers1) //{ // foreach (var player in players) // { // Console.WriteLine(player.FullName); // } //} //Console.WriteLine("-----------------------------------------------------------------"); //Find player with best avgPtsPerGame //1-st choice //var playerWithMostPointsPerGame = allPlayers // .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) // .ToList().FirstOrDefault(); // isto bi bilo da indeksirame so 0 indeks [0], za prviot da go dade vo listat //Console.WriteLine(playerWithMostPointsPerGame.FullName); #endregion // HOMEWORK //++++++++++++++++++++++++++++++++++++++++++++++++++++ // Find all coaches NAMES with Age > 50 //-------------------------------------- var coachesOver50 = teams .Where(team => team.Coach.Age > 50) .Select(team => team.Coach.FullName) .ToList(); coachesOver50.ForEach(fullName => Console.WriteLine(fullName)); Console.WriteLine("--->"); var coachesOver50Querry = (from team in teams where team.Coach.Age > 50 select team.Coach.FullName) .ToList(); coachesOver50Querry.ForEach(fullName => Console.WriteLine(fullName)); Console.WriteLine("-------------------------------------------------"); // Order players by AGE - DESC //---------------------------- var players = new List <Player>(); teams.ForEach(team => players.AddRange(team.Players)); var orderedPlayers = players .OrderByDescending(player => player.Age) .ToList(); orderedPlayers.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("--->"); var orderedPlayersQuerry = (from player in players orderby player.Age descending select player) .ToList(); orderedPlayersQuerry.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("-------------------------------------------------"); // Find player with highest RebPerGame //------------------------------------ var playerWithHighesrRebPerGame = players .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .FirstOrDefault(); Console.WriteLine(playerWithHighesrRebPerGame.FullName); Console.WriteLine("--->"); var playerWithHighesrRebPerGameQuerry = (from player in players orderby player.PlayerStatistic["RebPerGame"] descending select player) .First(); Console.WriteLine(playerWithHighesrRebPerGameQuerry.FullName); Console.WriteLine("-------------------------------------------------"); // Find all players with PtsPerGame > 20 //-------------------------------------- var playersWithPtsPerGameHigher20 = players .Where(player => player.PlayerStatistic["PtsPerGame"] > 20) .Select(player => player) .ToList(); playersWithPtsPerGameHigher20.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("--->"); var playersWithPtsPerGameHigher20Querry = (from player in players where player.PlayerStatistic["PtsPerGame"] > 20 select player) .ToList(); playersWithPtsPerGameHigher20Querry.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("--------------------------------------------------"); // Find all players NAMES older then 30 years //------------------------------------------- var playersOlder30 = players .Where(player => player.Age > 30) .Select(player => player.FullName) .ToList(); playersOlder30.ForEach(fullName => Console.WriteLine(fullName)); Console.WriteLine("--->"); var playersOlder30Querry = (from player in players where player.Age > 30 select player.FullName) .ToList(); playersOlder30Querry.ForEach(fullName => Console.WriteLine(fullName)); Console.WriteLine("---------------------------------------------------"); // Group players by age //--------------------- var groupedPlayersByAge = players .GroupBy(player => player.Age) .ToList(); foreach (var pair in groupedPlayersByAge) { Console.WriteLine(pair.Key); foreach (var player in pair) { Console.WriteLine($"------------{player.FullName}"); } } Console.WriteLine("---------------------------------------------------"); // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 //--------------------------------------------------------------- var playersWithRebPerGameOver7 = players .Where(player => player.PlayerStatistic["RebPerGame"] > 7.0f) .Select(player => new { Name = player.FullName, Points = player.PlayerStatistic["PtsPerGame"] }) .ToList(); playersWithRebPerGameOver7 .ForEach(namePts => Console.WriteLine($"{namePts.Name}: {namePts.Points} Points per game.")); Console.WriteLine("--->"); var playersWithRebPerGameOver7Querry = (from player in players where player.PlayerStatistic["RebPerGame"] > 7.0f select new { Name = player.FullName, Points = player.PlayerStatistic["PtsPerGame"] }) .ToList(); playersWithRebPerGameOver7Querry.ForEach(namePts => Console.WriteLine($"{namePts.Name}: {namePts.Points} Points per game.")); Console.WriteLine("----------------------------------------------------"); // Find first 3 players with highest PtsPerGame //--------------------------------------------- var first3PlayersWithHighestPtsPerGame = players .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Take(3) .ToList(); first3PlayersWithHighestPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("--->"); var first3PlayersWithHighestPtsPerGameQuerry = (from player in players orderby player.PlayerStatistic["PtsPerGame"] descending select player) .Take(3) .ToList(); first3PlayersWithHighestPtsPerGameQuerry.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("-----------------------------------------------------"); // Find the TEAM which has the player with highest PtsPerGame //----------------------------------------------------------- var playerWithHighestPtsPerGame = players .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .FirstOrDefault(); foreach (var team in teams) { foreach (var player in team.Players) { if (player.PlayerStatistic["PtsPerGame"] == playerWithHighestPtsPerGame.PlayerStatistic["PtsPerGame"]) { Console.WriteLine(team.Name); } } } Console.WriteLine("-----------------------------------------------------"); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC //--------------------------------------------------------------------------------- var first4PlayersWithHighestRebPerGameOrderedAscByPtsPerGame = players .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4) .OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); first4PlayersWithHighestRebPerGameOrderedAscByPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); Console.ReadLine(); }
static void Main(string[] args) { var teams = TeamsDataBase.GetAllTeams(); // Find all Teams with names starting with LA var findAllTeamsWithNamesStartingWithLA = teams .Where(team => team.Name.StartsWith("LA")).ToList(); findAllTeamsWithNamesStartingWithLA.ForEach(team => Console.WriteLine(team.Name)); // Find all team Names which are playing in "Staples Center" var findAllTeamNamesWhichPlayInStaplesCenter = teams .Where(team => team.Arena.Equals("Staples Center")) .Select(team => team.Name).ToList(); findAllTeamNamesWhichPlayInStaplesCenter.ForEach(team => Console.WriteLine(team)); // Find all teams coaches var allCoaches = teams.Select(team => team.Coach).ToList(); allCoaches.ForEach(coach => Console.WriteLine(coach.FullName)); // Find 3 oldest coaches names var oldest3CoachesNames = allCoaches.OrderByDescending(coach => coach.Age) .Take(3) .Select(coach => coach.FullName) .ToList(); oldest3CoachesNames.ForEach(trainerName => Console.WriteLine(trainerName)); // Group all teams by their arenas var groupedTeamsByArenas = teams.GroupBy(team => team.Arena).ToList(); foreach (var group in groupedTeamsByArenas) { Console.WriteLine($"{group.Key}"); foreach (var team in group) { Console.WriteLine($"----------{team.Name}"); } } // Find all players in one list var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); allPlayers.ForEach(player => Console.WriteLine(player.FullName)); // Find player with best avgPtsPerGame var playerWithMostPtsPerGame = allPlayers.OrderByDescending(player => player .PlayerStatistic["PtsPerGame"]).FirstOrDefault(); Console.WriteLine(playerWithMostPtsPerGame.FullName); // Find all coaches NAMES with Age > 50 var allCoachesNamesWithAgesOver50 = allCoaches .FindAll(coach => coach.Age > 50) .Select(coach => coach.FullName) .ToList(); allCoachesNamesWithAgesOver50.ForEach(coach => Console.WriteLine(coach)); // Order players by AGE - DESC var playersByAgeDesc = allPlayers.OrderByDescending(player => player.Age).ToList(); playersByAgeDesc.ForEach(player => Console.WriteLine(player.FullName)); // Find player with highest RebPerGame var playerWithHighestRebPerGame = allPlayers.OrderByDescending(player => player .PlayerStatistic["RebPerGame"]).FirstOrDefault(); Console.WriteLine(playerWithHighestRebPerGame.FullName); // Find all players with PtsPerGame > 20 var allPlayersWithPtsPerGameOver20 = allPlayers.FindAll(player => player .PlayerStatistic["PtsPerGame"] > 20) .Select(player => player.FullName) .ToList(); allPlayersWithPtsPerGameOver20.ForEach(player => Console.WriteLine(player)); // Find all players NAMES older then 30 years var allPlayersNamesOver30Years = allPlayers.FindAll(player => player.Age > 30).ToList(); allPlayersNamesOver30Years.ForEach(player => Console.WriteLine(player.FullName)); // Group players by age var groupPlayersByAge = allPlayers.GroupBy(player => player.Age).ToList(); foreach (var group in groupPlayersByAge) { Console.WriteLine($"{group.Key}"); foreach (var player in group) { Console.WriteLine($"-------------{player.FullName}"); } } // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var allPlayersNamesAndPtsPerGameIfRebPerGameOver7 = allPlayers .FindAll(player => player.PlayerStatistic["RebPerGame"] > 7.0) .ToList(); foreach (var player in allPlayersNamesAndPtsPerGameIfRebPerGameOver7) { Console.WriteLine($"{player.FullName} ---" + $" {player.PlayerStatistic["PtsPerGame"]}"); } // Find first 3 players with highest PtsPerGame var first3PlayersWithHighestPtsPerGame = allPlayers .OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]) .Take(3).ToList(); first3PlayersWithHighestPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); // Find the team which has the player with highest PtsPerGame var teamWhichHavePlayerWithHighestPtsPerGame = teams .Where(team => team.Players.Contains(playerWithMostPtsPerGame)) .Select(team => team.Name) .FirstOrDefault(); Console.WriteLine(teamWhichHavePlayerWithHighestPtsPerGame); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var first4PlayersWithHighestRebPerGameAndOrderByPtsPerGameAsc = allPlayers .OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4).OrderBy(player => player.PlayerStatistic["PtsPerGame"]) .ToList(); first4PlayersWithHighestRebPerGameAndOrderByPtsPerGameAsc.ForEach(player => Console.WriteLine(player.FullName)); Console.ReadLine(); }
static void Main(string[] args) { #region CLASS WORKSHOP var teams = TeamsDataBase.GetAllTeams(); //Find all Teams with name starting with LA var allTeamsLA = teams.Where(team => team.Name.StartsWith("LA")).ToList(); allTeamsLA.ForEach(team => Console.WriteLine(team.Name)); Console.WriteLine("----------------------------------------------------------"); //Find all team NAMES which are playing in "Steples Center" var allTeamsNamesSC = teams.Where(team => team.Arena.Equals("Staples Center")).Select(team => team.Name).ToList(); allTeamsNamesSC.ForEach(team => Console.WriteLine(team)); Console.WriteLine("----------------------------------------------------------"); //Find all teams coaches var allTeamCoatch = teams.Select(team => team.Coach).ToList(); allTeamCoatch.ForEach(coach => Console.WriteLine(coach.FullName)); Console.WriteLine("----------------------------------------------------------"); //Find 3 oldest coaches NAMES and AGE var oldest3Coatches = allTeamCoatch.OrderByDescending(coach => coach.Age).Take(3).Select(coach => new { coach.FullName, coach.Age }).ToList(); oldest3Coatches.ForEach(coach => Console.WriteLine(coach)); Console.WriteLine("----------------------------------------------------------"); //Group all teams by their Arena var groupAllTeamsByArena = teams.GroupBy(team => team.Arena).ToList(); foreach (var group in groupAllTeamsByArena) { Console.WriteLine($"{group.Key}"); foreach (var team in group) { Console.WriteLine($"-------{team.Name}"); } } Console.WriteLine("----------------------------------------------------------"); //Find all players in one LIST var allPlayers = new List <Player>(); teams.ForEach(team => allPlayers.AddRange(team.Players)); allPlayers.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("----------------------------------------------------------"); //Find player ranked by points with best avg Points var playerBestAvgPoints = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).FirstOrDefault(); Console.WriteLine(playerBestAvgPoints.FullName); Console.WriteLine("----------------------------------------------------------"); #endregion Console.ForegroundColor = ConsoleColor.Green; #region HOMEWORK // Find all coaches NAMES with Age > 50 var findCoachesNameAbove50 = allTeamCoatch.FindAll(coach => coach.Age > 50).ToList(); findCoachesNameAbove50.ForEach(coach => Console.WriteLine(coach.FullName)); Console.WriteLine("----------------------------------------------------------"); // Order players by AGE - DESC var playersOrderByAge = allPlayers.OrderByDescending(players => players.Age).Select(players => new { players.FullName, players.Age }).ToList(); playersOrderByAge.ForEach(player => Console.WriteLine(player)); Console.WriteLine("----------------------------------------------------------"); // Find player with highest RebPerGame var playerWithHighRebPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]).FirstOrDefault(); Console.WriteLine(playerWithHighRebPerGame.FullName); Console.WriteLine("----------------------------------------------------------"); // Find all players with PtsPerGame > 20 var allPlayerPtsPerGame20Higher = allPlayers.Where(player => player.PlayerStatistic["PtsPerGame"] > 20).Select(player => player.FullName).ToList(); allPlayerPtsPerGame20Higher.ForEach(player => Console.WriteLine(player)); Console.WriteLine("----------------------------------------------------------"); // Find all players NAMES older then 30 years var playerNamesOlder30 = allPlayers.Where(player => player.Age > 30).Select(player => player.FullName).ToList(); playerNamesOlder30.ForEach(player => Console.WriteLine(player)); Console.WriteLine("----------------------------------------------------------"); // Group players by age var groupPlayerByAge = allPlayers.GroupBy(player => player.Age).ToList(); foreach (var playerAge in groupPlayerByAge) { Console.WriteLine(playerAge.Key); foreach (var player in playerAge) { Console.WriteLine(player.FullName); } } ; Console.WriteLine("----------------------------------------------------------"); // Find All players NAMES and PtsPerGame if have RebPerGame > 7.0 var playerNamesPtsIfRebPerGame7High = (from player in allPlayers where player.PlayerStatistic["RebPerGame"] > 7 select player).Select(player => new { Name = player.FullName, Points = player.PlayerStatistic["PtsPerGame"] }).ToList(); playerNamesPtsIfRebPerGame7High.ForEach(player => Console.WriteLine(player)); Console.WriteLine("----------------------------------------------------------"); // Find first 3 players with highest PtsPerGame var player3HighestPtsPerGame = allPlayers.OrderByDescending(player => player.PlayerStatistic["PtsPerGame"]).Take(3).ToList(); player3HighestPtsPerGame.ForEach(player => Console.WriteLine(player.FullName)); Console.WriteLine("----------------------------------------------------------"); // Find the team which has the player with highest PtsPerGame var teamHasPlayerHighestPoints = teams.SingleOrDefault(team => team.Players.Contains(playerBestAvgPoints)); Console.WriteLine(teamHasPlayerHighestPoints.Name); Console.WriteLine("----------------------------------------------------------"); // Find first 4 players with highest RebPerGame and order them by PtsPerGame - ASC var first4PlayersHighestReb = allPlayers.OrderByDescending(player => player.PlayerStatistic["RebPerGame"]) .Take(4).OrderBy(player => player.PlayerStatistic["PtsPerGame"]).ToList(); first4PlayersHighestReb.ForEach(player => Console.WriteLine(player.FullName)); #endregion Console.ReadLine(); }