-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.cs
73 lines (53 loc) · 1.64 KB
/
List.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
namespace Week14Repetition.Iteration
{
class Program
{
static void Main()
{
List<int> a = new List<int>() { 1, 1, 2, 3 };
for (int i = 0; i < a.Count; i++)
{
Console.Write($"{a[i]} ");
}
Console.WriteLine();
while (true)
{
int input = Convert.ToInt32(Console.ReadLine());
if (input == -1)
{
break;
}
a.Add(input);
}
foreach (int n in a)
{
Console.Write($"{n} ");
}
Console.WriteLine();
if (a.Contains(5))
{
Console.WriteLine("a does contains a 5");
}
else
{
Console.WriteLine("a does not contain a 5");
}
Console.WriteLine($"first = {a.IndexOf(3)}, last = {a.LastIndexOf(3)}");
while (a.Remove(1))
{
Console.WriteLine("Removed a 1");
}
Console.WriteLine(string.Join(", ", a));
a.RemoveAt(0);
Console.WriteLine(string.Join(", ", a));
a.RemoveAt(a.Count - 1);
Console.WriteLine(string.Join(", ", a));
a.Sort();
Console.WriteLine(string.Join(", ", a));
a.Clear();
Console.WriteLine(string.Join(", ", a));
}
}
}