From 2cec7ca136f0e0b00d32eb4ef219f71119eb73ff Mon Sep 17 00:00:00 2001 From: "g.isachenko" Date: Sat, 8 Feb 2020 17:40:06 +0200 Subject: [PATCH 1/4] Change for to Sum() in sum calculator --- nice-project/ImportantStuff.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/nice-project/ImportantStuff.cs b/nice-project/ImportantStuff.cs index 9b75911..e945038 100644 --- a/nice-project/ImportantStuff.cs +++ b/nice-project/ImportantStuff.cs @@ -16,14 +16,7 @@ public int DoWhatNeedsToBeDone(IFileReader fileReader) private int CalculateSumOf(IEnumerable allNumbers) { - var list = allNumbers.ToList(); - var sum = 0; - for (int i = 0; i < list.Count; i++) - { - sum += list[i]; - } - - return sum; + return allNumbers.Sum(); } } } \ No newline at end of file From b3653009b9cc5d241d43a286d89a3f467388644d Mon Sep 17 00:00:00 2001 From: "g.isachenko" Date: Sat, 8 Feb 2020 18:08:28 +0200 Subject: [PATCH 2/4] Add some strange file reader that returns the length of file --- nice-project/SomeStrangeFileReader.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 nice-project/SomeStrangeFileReader.cs diff --git a/nice-project/SomeStrangeFileReader.cs b/nice-project/SomeStrangeFileReader.cs new file mode 100644 index 0000000..30cfa05 --- /dev/null +++ b/nice-project/SomeStrangeFileReader.cs @@ -0,0 +1,21 @@ +namespace NiceProject +{ + using System.Collections.Generic; + using System.IO; + + public class SomeStrangeFileReader : IFileReader + { + private string path; + + public SomeStrangeFileReader(string path) + { + this.path = path; + } + + public IEnumerable ReadAllNumbers() + { + FileInfo fi = new FileInfo(path); + yield return (int) fi.Length; + } + } +} \ No newline at end of file From 594f542ee04721b2b5372d5cd299e50c04623237 Mon Sep 17 00:00:00 2001 From: "g.isachenko" Date: Sat, 8 Feb 2020 18:09:56 +0200 Subject: [PATCH 3/4] Add waiting for user input after program has run --- nice-project/Program.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nice-project/Program.cs b/nice-project/Program.cs index 5da6ef6..5f86d96 100644 --- a/nice-project/Program.cs +++ b/nice-project/Program.cs @@ -14,6 +14,9 @@ static void Main(string[] args) var result = stuff.DoWhatNeedsToBeDone(fileReader); Console.WriteLine($"Result is {result}"); + + // Wait for input + Console.ReadLine(); } } } \ No newline at end of file From e271e608c1b99ebf566ae3ed9fab13cbe46491f6 Mon Sep 17 00:00:00 2001 From: "g.isachenko" Date: Sat, 8 Feb 2020 18:08:28 +0200 Subject: [PATCH 4/4] Add some strange file reader that returns the length of file