-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.cs
More file actions
74 lines (62 loc) · 1.84 KB
/
Dictionary.cs
File metadata and controls
74 lines (62 loc) · 1.84 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
namespace Week14Repetition.Iteration
{
class Program
{
static void Main()
{
Dictionary<char, string> a = new Dictionary<char, string>()
{
{ 'a', "Alpha" },
{ 'b', "Beta" },
{ 'c', "Charlie" },
{ 'd', "Delta" }
};
foreach (KeyValuePair<char,string> entry in a)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
while (true)
{
char key = Console.ReadKey().KeyChar;
if (key == ' ')
{
break;
}
string value = Console.ReadLine();
a.Add(key, value);
}
Console.WriteLine();
foreach (KeyValuePair<char,string> entry in a)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
if (a.ContainsKey('e'))
{
Console.WriteLine("a does contain an entry with the key a");
}
else
{
Console.WriteLine("a does not contain an entry with the key a");
}
if (a.ContainsValue("Charlie"))
{
Console.WriteLine("a does contain an entry with the value Charlie");
}
else
{
Console.WriteLine("a does contain an entry with the value Charlie");
}
if (a.TryGetValue('f', out string v))
{
Console.WriteLine(v);
}
else
{
Console.WriteLine("a does not contain an entry with the key f");
}
a.Remove('a');
}
}
}