private void JoinPurchasesWithPrices() { IEnumerable <Comic> comics = BuildCatalog(); Dictionary <int, decimal> values = GetPrices(); IEnumerable <Purchase> purchases = Purchases.FindPurchases(); var results = from comic in comics join purchase in purchases on comic.Issue equals purchase.Issue orderby comic.Issue ascending select new { comic.Name, comic.Issue, purchase.Price }; decimal gregsListValue = 0; decimal totalSpent = 0; foreach (var result in results) { gregsListValue += values[result.Issue]; totalSpent += result.Price; string messagFOrQueryResult = String.Format("Issue #{0} {1} bought for {2:c}", result.Issue, result.Name, result.Price); CurrentQueryResults.Add(CreateAnonymousListViewItem(messagFOrQueryResult, "captain_amazing_250x250.jpg")); } string message = String.Format("I spent {0:c} on comics worth {1:c}", totalSpent, gregsListValue); CurrentQueryResults.Add(CreateAnonymousListViewItem(message, "captain_amazing_250x250.jpg")); }
private void JoinPurchasesWithPrices() { var comics = BuildCatalog(); var values = GetPrices(); var purchases = Purchase.FindPurchases(); var results = from comic in comics join purchase in purchases on comic.Issue equals purchase.Issue orderby comic.Issue ascending select new { Comic = comic, Price = purchase.Price, Title = comic.Name, Subtitle = "Issue #" + comic.Issue, Description = $"Bought for {purchase.Price:c}", Image = CreateImageFromAssets("captain_amazing_250x250.jpg"), }; decimal gregsListValue = 0; decimal totalSpent = 0; foreach (var result in results) { gregsListValue += values[result.Comic.Issue]; totalSpent += result.Price; CurrentQueryResults.Add(result); } Title = $"I spent {totalSpent:c} on comics worth {gregsListValue:c}"; }
private void JoinPurchasesWithPrices() { IEnumerable <Comic> comics = BuildCatalog(); Dictionary <int, decimal> values = GetPrices(); IEnumerable <Purchase> purchases = Purchase.FindPurchases(); var results = from comic in comics join purchase in purchases on comic.Issue equals purchase.Issue orderby comic.Issue ascending select new { Comic = comic, Price = purchase.Price, Title = comic.Name, Subtitle = "Issue #" + comic.Issue, Description = String.Format("Bought for {0:c}", purchase.Price), Image = CreateImageFromAssets("captain_amazing_250x250.jpg"), }; decimal gregsListValue = 0; decimal totalSpent = 0; foreach (var result in results) { gregsListValue += values[result.Comic.Issue]; totalSpent += result.Price; CurrentQueryResults.Add(result); } Title = String.Format("I spent {0:c} on comics worth {1:c}", totalSpent, gregsListValue); }
private void AllComics() { foreach (Comic comic in BuildCatalog()) { var result = new { ImagePath = "Assets/captain_amazing_250x250.jpg", Title = comic.Name, Subtitle = "Issue #" + comic.Issue, Description = "The Captain versus " + comic.MainVillain, Comic = comic, }; CurrentQueryResults.Add(result); } }
private void LinqIsVersatile1() { string[] sandwiches = { "ham and cheese", "salami with mayo", "turkey and swiss", "chicken cutlet" }; var sandwichesOnRye = from sandwich in sandwiches select sandwich + " on rye"; foreach (var sandwich in sandwichesOnRye) { CurrentQueryResults.Add(CreateAnonymousListViewItem(sandwich, "bluegray_250x250.jpg")); } }
private void LinqIsVersatile1() { string[] sandwiches = { "szynka i ser", "salami z majonezem", "indyk i ser szwajcarski", "kotlet z kurczaka" }; var sandwichesOnRye = from sandwich in sandwiches select sandwich + " na chlebie zborzowym"; CurrentQueryResults.Clear(); foreach (var sandwich in sandwichesOnRye) { CurrentQueryResults.Add(CreateAnonymousListViewItem(sandwich, "bluegray_250x250.jpg")); } }
private void LinqMakesQueriesEasy() { int[] values = new int[] { 0, 12, 44, 36, 92, 54, 13, 8 }; var results = from v in values where v < 37 orderby v select v; CurrentQueryResults.Clear(); foreach (int i in results) { CurrentQueryResults.Add(new { Title = i.ToString(), Image = CreateImageFromAssets("purple_250x250.jpg") }); //File Name } }
private void LinqIsVersatile1() { string[] sandwiches = { "ham and cheese", "salami with mayo", "turkey and swiss", "chicken cutlet" }; var sandwichesOnRye = from sandwich in sandwiches select sandwich + " on rye"; CurrentQueryResults.Clear(); foreach (var sandwich in sandwichesOnRye) { CurrentQueryResults.Add(CreateAnonymousListViewItem(sandwich, @"F:\Programs\IT\Programming Language\C#\hfcs\chap14\LinqSplitApp\bluegray_250x250.jpg")); } }
private void ExpensiveComics() { IEnumerable <Comic> comics = BuildCataloq(); Dictionary <int, decimal> values = GetPrices(); var mostExpensive = from comic in comics where values[comic.Issue] > 500 orderby values[comic.Issue] select comic; CurrentQueryResults.Clear(); foreach (Comic comic in mostExpensive) { CurrentQueryResults.Add(new { Title = string.Format("{0} is worth {1:c}", comic.Name, values[comic.Issue]), Image = CreateImageFromAssets("captain_amazing_250x250.jpg") }); } }
private void AllComics() { foreach (Comic comic in BuildCatalog()) { var result = new { Image = CreateImageFromAssets("captain_amazing_zoom_250x250.jpg"), Title = comic.Name, Subtitle = "Numer " + comic.Issue, Description = "Kapitan Wspaniały kontra " + comic.MainVillain, Comic = comic, }; CurrentQueryResults.Add(result); } }
private void AllComics() { foreach (Comic comic in BuildCatalog()) { var result = new { Image = CreateImageFromAssets("captain_amazing_zoom_250x250.jpg"), Title = comic.Name, Subtitle = $"Issue #{comic.Issue}", Description = $"The Captain versus {comic.MainVillain}", Comic = comic, }; CurrentQueryResults.Add(result); } }
private void LinqMakesQueriesEasy() { int[] values = new int[] { 0, 12, 44, 36, 92, 54, 13, 8 }; var result = from v in values where v < 37 orderby v select v; CurrentQueryResults.Clear(); foreach (int i in result) { CurrentQueryResults.Add( new { Title = i.ToString(), ImagePath = "Assets/purple_250x250.jpg", }); } }
private void AllComics() { foreach (Comic comic in BuildCatalog()) { var result = new { Image = CreateImageFromAssets(@"F:\Programs\IT\Programming Language\C#\hfcs\chap14\LinqSplitApp\captain_amazing_zoom_250x250.jpg"), Title = comic.Name, Subtitle = "Issue #" + comic.Issue, Description = "The Captain versus " + comic.MainVillain, Comic = comic, }; CurrentQueryResults.Add(result); } }
private void LinqIsVersatile2() { Random random = new Random(); List <int> listOfNumbers = new List <int>(); int length = random.Next(50, 150); for (int i = 0; i < length; i++) { listOfNumbers.Add(random.Next(100)); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("There are {0} numbers", listOfNumbers.Count()))); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("The smallest is {0}", listOfNumbers.Min()))); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("The biggest is {0}", listOfNumbers.Max()))); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("The sum is {0}", listOfNumbers.Sum()))); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("The average is {0:F2}", listOfNumbers.Average()))); } }
private void LinqIsVersatile3() { List <int> listOfNumbers = new List <int>(); for (int i = 1; i <= 10000; i++) { listOfNumbers.Add(i); } var under50sorted = from number in listOfNumbers where number < 50 orderby number descending select number; var firsFive = under50sorted.Take(6); List <int> shortList = firsFive.ToList(); foreach (int n in shortList) { CurrentQueryResults.Add(CreateAnonymousListViewItem(n.ToString(), "bluegray_250x250.jpg")); } }
private void ExpensiveComics() { IEnumerable <Comic> comics = BuildCatalog(); Dictionary <int, decimal> values = GetPrices(); var mostExpensive = from comic in comics where values[comic.Issue] > 500 orderby values[comic.Issue] descending select comic; CurrentQueryResults.Clear(); foreach (Comic comic in mostExpensive) { CurrentQueryResults.Add( new { Title = string.Format("{0} is worth {1:c}", comic.Name, values[comic.Issue]), ImagePath = "Assets/purple_250x250.jpg", }); } }
private void CombineJimmysValuesIntoGroups() { Dictionary <int, decimal> values = GetPrices(); var priceGroups = from pair in values group pair.Key by Purchase.EvaluatePrice(pair.Value) into priceGroup orderby priceGroup.Key descending select priceGroup; foreach (var group in priceGroups) { string message = String.Format("I found {0} {1} comics: issues ", group.Count(), group.Key); foreach (var price in group) { message += price.ToString() + "; "; } CurrentQueryResults.Add(CreateAnonymousListViewItem(message, "capitan_amazing_250x250.jpg")); } }
private void LinqMakesQueriesEasy() { int[] values = new int[] { 0, 12, 44, 36, 92, 54, 13, 8 }; var result = from v in values where v < 37 orderby v select v; CurrentQueryResults.Clear(); foreach (int i in result) { CurrentQueryResults.Add( new { Title = i.ToString(), Image = CreateImageFromAssets(@"F:\Programs\IT\Programming Language\C#\hfcs\chap14\LinqSplitApp\purple_250x250.jpg"), } ); } }
private void GroupComicsByRange() { Dictionary <int, decimal> values = GetPrices(); var priceGroups = from pair in values group pair.Key by Purchases.EvaluatePrice(pair.Value) into priceGroup orderby priceGroup.Key descending select priceGroup; foreach (var group in priceGroups) { string message = String.Format("I found {0} {1} comics: issue ", group.Count(), group.Key); foreach (var issueNumber in group) { message += $"{issueNumber.ToString()} "; } CurrentQueryResults.Add(CreateAnonymousListViewItem(message, "captain_amazing_250x250.jpg")); } }
private void CombineJimmysValuesIntoGroups() { var values = GetPrices(); var priceGroups = from pair in values group pair.Key by Purchase.EvaluatePrice(pair.Value) into priceGroup orderby priceGroup.Key descending select priceGroup; foreach (var group in priceGroups) { var message = $"I found {@group.Count()} {@group.Key} comics: issues "; foreach (var price in group) { message += price.ToString() + " "; } CurrentQueryResults.Add( CreateAnonymousListViewItem(message, "captain_amazing_250x250.jpg")); } }
private void LinqIsVersatile2() { Random random = new Random(); List <int> listOfNumbers = new List <int>(); int length = random.Next(50, 150); for (int i = 0; i < length; i++) { listOfNumbers.Add(random.Next(100)); } CurrentQueryResults.Clear(); CurrentQueryResults.Add(CreateAnonymousListViewItem( String.Format("Na liście znajduje się {0} liczb", listOfNumbers.Count()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Najmniejsza z nich to {0}", listOfNumbers.Min()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Największa z nich to {0}", listOfNumbers.Max()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Suma wynosi {0}", listOfNumbers.Sum()))); CurrentQueryResults.Add(CreateAnonymousListViewItem(String.Format("Średnia wynosi {0:F2}", listOfNumbers.Average()))); }
private void ExpensiveComics() { var comics = BuildCatalog(); var values = GetPrices(); var mostExpensive = from comic in comics where values[comic.Issue] > 500 orderby values[comic.Issue] descending select comic; CurrentQueryResults.Clear(); foreach (var comic in mostExpensive) { CurrentQueryResults.Add( new { Title = $"{comic.Name} is worth {values[comic.Issue]:c}", Image = CreateImageFromAssets("captain_amazing_250x250.jpg"), } ); } }
private void JoinPurchasesWithPrices() { Dictionary <int, decimal> values = GetPrices(); var priceGroups = from pair in values group pair.Key by Purchase.EvaluatePrice(pair.Value) into priceGroup orderby priceGroup.Key descending select priceGroup; foreach (var group in priceGroups) { string message = String.Format("Найдены {0} {1} комиксов: выпуски ", group.Count(), group.Key); foreach (var price in group) { message += price.ToString() + " "; } CurrentQueryResults.Add( CreateAnonymousListViewItem(message, "captain_amazing_250x250.jpg")); } }
private void LinqIsVersatile2() { var random = new Random(); var listOfNumbers = new List <int>(); var length = random.Next(50, 150); for (var i = 0; i < length; i++) { listOfNumbers.Add(random.Next(100)); } CurrentQueryResults.Clear(); CurrentQueryResults.Add( CreateAnonymousListViewItem($"There are {listOfNumbers.Count} numbers")); CurrentQueryResults.Add( CreateAnonymousListViewItem($"The smallest is {listOfNumbers.Min()}")); CurrentQueryResults.Add( CreateAnonymousListViewItem($"The biggest is {listOfNumbers.Max()}")); CurrentQueryResults.Add( CreateAnonymousListViewItem($"The sum is {listOfNumbers.Sum()}")); CurrentQueryResults.Add( CreateAnonymousListViewItem($"The average is {listOfNumbers.Average():F2}")); }
private void LinqIsVersatile2() { Random random = new Random(); List <int> listOfNumbers = new List <int>(); int length = random.Next(50, 150); for (int i = 0; i < length; i++) { listOfNumbers.Add(random.Next(100)); } CurrentQueryResults.Clear(); CurrentQueryResults.Add(CreateAnonymousListViewItem( String.Format("Dostępnych jest {0} liczb", listOfNumbers.Count()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Najmniejsza wartość to: {0}", listOfNumbers.Min()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Największa wartość to: {0}", listOfNumbers.Max()))); CurrentQueryResults.Add( CreateAnonymousListViewItem(String.Format("Suma wartości: {0}", listOfNumbers.Sum()))); CurrentQueryResults.Add(CreateAnonymousListViewItem( String.Format("Wartość średnia to: {0:F2}", listOfNumbers.Average()))); }
private void ExpensiveComics() { IEnumerable <Comic> comics = BuildCatalog(); Dictionary <int, decimal> values = GetPrices(); var mostExpensive = from comic in comics where values[comic.Issue] > 500 orderby values[comic.Issue] descending select comic; CurrentQueryResults.Clear(); foreach (Comic comic in mostExpensive) { CurrentQueryResults.Add( new { Title = String.Format("{0} is worth {1:c}", comic.Name, values[comic.Issue]), Image = CreateImageFromAssets(@"F:\Programs\IT\Programming Language\C#\hfcs\chap14\LinqSplitApp\captain_amazing_250x250.jpg"), } ); } }
private void CombineJimmysValuesIntoGroups() { Dictionary <int, decimal> values = GetPrices(); var priceGroups = from pair in values group pair.Key by Purchase.EvaluatePrice(pair.Value) into priceGroup orderby priceGroup.Key descending select priceGroup; foreach (var group in priceGroups) { string stringKey; switch (group.Key) { case PriceRange.Cheap: stringKey = "tanie"; break; case PriceRange.Midrange: stringKey = "średnie"; break; default: stringKey = "drogie"; break; } string message = String.Format("Znalazłem {0} {1} komiksy: numery ", group.Count(), stringKey); foreach (var price in group) { message += price.ToString() + " "; } CurrentQueryResults.Add( CreateAnonymousListViewItem(message, "captain_amazing_250x250.jpg")); } }