From 951ca5f313c497d0322c06802db39a42c5e51287 Mon Sep 17 00:00:00 2001 From: Radek Date: Wed, 9 May 2018 20:29:33 +0200 Subject: [PATCH] Reformat code --- csharp/GildedRose.cs | 78 +++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index c60d97a0..9458a37d 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -4,83 +4,87 @@ namespace csharp { public class GildedRose { - IList Items; - public GildedRose(IList Items) - { - this.Items = Items; - } + private readonly IList _items; + + public GildedRose(IList items) + => _items = items; public void UpdateQuality() { - for (var i = 0; i < Items.Count; i++) + foreach (var item in _items) { - if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.Name != "Aged Brie" + && item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Quality > 0) + if (item.Quality > 0) { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + if (item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].Quality = Items[i].Quality - 1; + item.Quality = item.Quality - 1; } } } else { - if (Items[i].Quality < 50) + if (item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + item.Quality = item.Quality + 1; - if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert") + if (item.Name == "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].SellIn < 11) + if (item.SellIn < 11) { - if (Items[i].Quality < 50) + if (item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + item.Quality = item.Quality + 1; } } - if (Items[i].SellIn < 6) + if (item.SellIn < 6) { - if (Items[i].Quality < 50) + if (item.Quality < 50) { - Items[i].Quality = Items[i].Quality + 1; + item.Quality = item.Quality + 1; } } } } } - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") + if (item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].SellIn = Items[i].SellIn - 1; + item.SellIn = item.SellIn - 1; } - if (Items[i].SellIn < 0) + if (item.SellIn >= 0) { - if (Items[i].Name != "Aged Brie") + continue; + } + + if (item.Name != "Aged Brie") + { + if (item.Name != "Backstage passes to a TAFKAL80ETC concert") { - if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") + if (item.Quality <= 0) { - if (Items[i].Quality > 0) - { - if (Items[i].Name != "Sulfuras, Hand of Ragnaros") - { - Items[i].Quality = Items[i].Quality - 1; - } - } + continue; } - else + + if (item.Name != "Sulfuras, Hand of Ragnaros") { - Items[i].Quality = Items[i].Quality - Items[i].Quality; + item.Quality = item.Quality - 1; } } else { - if (Items[i].Quality < 50) - { - Items[i].Quality = Items[i].Quality + 1; - } + item.Quality = item.Quality - item.Quality; + } + } + else + { + if (item.Quality < 50) + { + item.Quality = item.Quality + 1; } } }