-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson35.cs
More file actions
54 lines (47 loc) · 1.62 KB
/
Lesson35.cs
File metadata and controls
54 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
namespace Tired
{
class Program
{
static void Main(string[] args)
{
const string ExitWord = "exit";
const string SumWord = "sum";
string currentWord = "";
List<int> numberList = new List<int>();
Console.WriteLine("Введите число чтобы добавить его в список или " + ExitWord + " или " + SumWord + " для выполнения команд");
while (currentWord != ExitWord)
{
Console.Write("Значение:");
currentWord = Console.ReadLine();
if( currentWord == ExitWord)
{
continue;
}
else if(currentWord == SumWord)
{
Console.WriteLine("Сумма всего списка равна:" + SumList(numberList));
}
else if(Int32.TryParse(currentWord, out int parsedValue) == true)
{
numberList.Add(parsedValue);
Console.WriteLine("Значение добавлено!");
}
else
{
Console.WriteLine("Не удалось добавить значение!");
}
}
}
private static int SumList(List<int> selectedList)
{
int result = 0;
foreach(int number in selectedList)
{
result += number;
}
return result;
}
}
}