forked from ProfessionalCSharp/ProfessionalCSharp7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
67 lines (57 loc) · 1.99 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace Wrox.ProCSharp.Collections
{
class Program
{
static void Main()
{
var idJimmie = new EmployeeId("C48");
var jimmie = new Employee(idJimmie, "Jimmie Johnson", 150926.00m);
var idJoey = new EmployeeId("F22");
var joey = new Employee(idJoey, "Joey Logano", 45125.00m);
var idKyle = new EmployeeId("T18");
var kyle = new Employee(idKyle, "Kyle Bush", 78728.00m);
var idCarl = new EmployeeId("T19");
var carl = new Employee(idCarl, "Carl Edwards", 80473.00m);
var idMatt = new EmployeeId("T20");
var matt = new Employee(idMatt, "Matt Kenseth", 113970.00m);
var employees = new Dictionary<EmployeeId, Employee>(31)
{
[idJimmie] = jimmie,
[idJoey] = joey,
[idKyle] = kyle,
[idCarl] = carl,
[idMatt] = matt
};
foreach (var employee in employees.Values)
{
Console.WriteLine(employee);
}
while (true)
{
Console.Write("Enter employee id (X to exit)> ");
var userInput = Console.ReadLine();
userInput = userInput.ToUpper();
if (userInput == "X") break;
EmployeeId id;
try
{
id = new EmployeeId(userInput);
if (!employees.TryGetValue(id, out Employee employee))
{
Console.WriteLine($"Employee with id {id} does not exist");
}
else
{
Console.WriteLine(employee);
}
}
catch (EmployeeIdException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}