From 584fd2c0d8fdbf4e7691988feaa14b09cceb772c Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sun, 19 Mar 2023 00:08:23 +0200 Subject: [PATCH] Simplify Lesson 1 Task 3 --- Lesson_1/Task_3/Program.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Lesson_1/Task_3/Program.cs b/Lesson_1/Task_3/Program.cs index 6105750..d6818d8 100644 --- a/Lesson_1/Task_3/Program.cs +++ b/Lesson_1/Task_3/Program.cs @@ -6,7 +6,6 @@ int duplicate; List numbers = new List(); -string? userInput; for (int i = 0; i < 10; i++) { @@ -14,9 +13,8 @@ for (int i = 0; i < 10; i++) do { - Console.Write(string.Format("Enter number {0}: ", i + 1)); - userInput = Console.ReadLine(); - } while (!int.TryParse(userInput, out newNumber)); + Console.Write($"Enter number {i + 1}: "); + } while (!int.TryParse(Console.ReadLine(), out newNumber)); numbers.Add(newNumber); } @@ -24,8 +22,7 @@ for (int i = 0; i < 10; i++) do { Console.Write("Enter a number to duplicate: "); - userInput = Console.ReadLine(); -} while (!int.TryParse(userInput, out duplicate)); +} while (!int.TryParse(Console.ReadLine(), out duplicate)); for (int i = 0; i < numbers.Count; i++) { if (numbers[i] == duplicate) @@ -35,8 +32,4 @@ for (int i = 0; i < numbers.Count; i++) { } } -Console.WriteLine( - string.Join(", ", - numbers.Select(number => number.ToString()) - ) -); +Console.WriteLine(String.Join(", ", numbers));