예제 #1
0
파일: Program.cs 프로젝트: xiongfj/Backup
        static void Main()
        {
            // EmloyeeId 是自定义的键类
            var employees = new Dictionary <EmployeeId, Employee>(31);

            var idTony = new EmployeeId("C3755");
            var tony   = new Employee(idTony, "Tony Stewart", 379025.00m);

            employees.Add(idTony, tony);
            Console.WriteLine(tony);

            var idCarl = new EmployeeId("F3547");
            var carl   = new Employee(idCarl, "Carl Edwards", 403466.00m);

            employees.Add(idCarl, carl);
            Console.WriteLine(carl);

            var idKevin = new EmployeeId("C3386");
            var kevin   = new Employee(idKevin, "Kevin Harwick", 415261.00m);

            employees.Add(idKevin, kevin);
            Console.WriteLine(kevin);

            var idMatt = new EmployeeId("F3323");
            var matt   = new Employee(idMatt, "Matt Kenseth", 1589390.00m);

            employees[idMatt] = matt;
            Console.WriteLine(matt);

            var idBrad = new EmployeeId("D3234");
            var brad   = new Employee(idBrad, "Brad Keselowski", 322295.00m);

            employees[idBrad] = brad;
            Console.WriteLine(brad);



            //while (true)
            {
                // Console.Write("Enter employee id (X to exit)> ");
                //var userInput = Console.ReadLine();
                string userInput = "D3234";
                // if (userInput == "X") break;

                EmployeeId id;
                try
                {
                    id = new EmployeeId(userInput);


                    Employee employee;
                    if (!employees.TryGetValue(id, out employee))
                    {
                        Console.WriteLine("Employee with id {0} does not exist", id);
                    }
                    else
                    {
                        Console.WriteLine(employee);
                    }
                }
                catch (EmployeeIdException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
예제 #2
0
 public Employee(EmployeeId id, string name, decimal salary)
 {
     this.id     = id;
     this.name   = name;
     this.salary = salary;
 }
        static void Main()
        {
            var idTony = new EmployeeId("C3755");
            var tony   = new Employee(idTony, "Tony Stewart", 379025.00m);

            var idCarl = new EmployeeId("F3547");
            var carl   = new Employee(idCarl, "Carl Edwards", 403466.00m);

            var idKevin = new EmployeeId("C3386");
            var kevin   = new Employee(idKevin, "Kevin Harwick", 415261.00m);

            var idMatt = new EmployeeId("F3323");
            var matt   = new Employee(idMatt, "Matt Kenseth", 1589390.00m);

            var idBrad = new EmployeeId("D3234");
            var brad   = new Employee(idBrad, "Brad Keselowski", 322295.00m);

            var employees = new Dictionary <EmployeeId, Employee>(31)
            {
                [idTony]  = tony,
                [idCarl]  = carl,
                [idKevin] = kevin,
                [idMatt]  = matt,
                [idBrad]  = brad
            };

            foreach (var employee in employees.Values)
            {
                WriteLine(employee);
            }

            while (true)
            {
                Write("Enter employee id (X to exit)> ");
                var userInput = ReadLine();
                userInput = userInput.ToUpper();
                if (userInput == "X")
                {
                    break;
                }

                EmployeeId id;
                try
                {
                    id = new EmployeeId(userInput);


                    Employee employee;
                    if (!employees.TryGetValue(id, out employee))
                    {
                        WriteLine("Employee with id {0} does not exist", id);
                    }
                    else
                    {
                        WriteLine(employee);
                    }
                }
                catch (EmployeeIdException ex)
                {
                    WriteLine(ex.Message);
                }
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: zilo312/aa
        static void Main()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            Dictionary <EmployeeId, Employee> employees =
                new Dictionary <EmployeeId, Employee>(31);

            EmployeeId idJeff = new EmployeeId("C7102");
            Employee   jeff   = new Employee(idJeff, "Jeff Gordon",
                                             5164580.00m);

            employees.Add(idJeff, jeff);
            Console.WriteLine(jeff);

            EmployeeId idTony = new EmployeeId("C7105");
            Employee   tony   = new Employee(idTony, "Tony Stewart", 4814200.00m);

            employees.Add(idTony, tony);
            Console.WriteLine(tony);

            EmployeeId idDenny = new EmployeeId("C8011");
            Employee   denny   = new Employee(idDenny, "Denny Hamlin", 3718710.00m);

            employees.Add(idDenny, denny);
            Console.WriteLine(denny);

            EmployeeId idCarl = new EmployeeId("F7908");
            Employee   carl   = new Employee(idCarl, "Carl Edwards", 3285710.00m);

            employees[idCarl] = carl;
            Console.WriteLine(carl);

            EmployeeId idMatt = new EmployeeId("F7203");
            Employee   matt   = new Employee(idMatt, "Matt Kenseth", 4520330.00m);

            employees[idMatt] = matt;
            Console.WriteLine(matt);


            while (true)
            {
                try
                {
                    Console.Write("Enter employee id (X to exit)> ");
                    string userInput = Console.ReadLine();
                    userInput = userInput.ToUpper();
                    if (userInput == "X")
                    {
                        break;
                    }
                    EmployeeId id = new EmployeeId(userInput);

                    Employee employee;
                    if (!employees.TryGetValue(id, out employee))
                    {
                        Console.WriteLine("Employee with id {0} does not exist",
                                          id);
                    }
                    else
                    {
                        Console.WriteLine(employee);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                }
            }
        }
 public Employee(EmployeeId id, string name, decimal salary)
 {
     _id     = id;
     _name   = name;
     _salary = salary;
 }
예제 #6
0
        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);
                }
            }
        }
예제 #7
0
        static void Main()
        {
            var employees = new Dictionary <EmployeeId, Employee>(31);

            var idKyle = new EmployeeId("T3755");
            var kyle   = new Employee(idKyle, "Kyle Bush", 5443890.00m);

            employees.Add(idKyle, kyle);
            Console.WriteLine(kyle);

            var idCarl = new EmployeeId("F3547");
            var carl   = new Employee(idCarl, "Carl Edwards", 5597120.00m);

            employees.Add(idCarl, carl);
            Console.WriteLine(carl);

            var idJimmie = new EmployeeId("C3386");
            var jimmie   = new Employee(idJimmie, "Jimmie Johnson", 5024710.00m);

            employees.Add(idJimmie, jimmie);
            Console.WriteLine(jimmie);

            var idDale = new EmployeeId("C3323");
            var dale   = new Employee(idDale, "Dale Earnhardt Jr.", 3522740.00m);

            employees[idDale] = dale;
            Console.WriteLine(dale);

            var idJeff = new EmployeeId("C3234");
            var jeff   = new Employee(idJeff, "Jeff Burton", 3879540.00m);

            employees[idJeff] = jeff;
            Console.WriteLine(jeff);



            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);


                    Employee employee;
                    if (!employees.TryGetValue(id, out employee))
                    {
                        Console.WriteLine("Employee with id {0} does not exist", id);
                    }
                    else
                    {
                        Console.WriteLine(employee);
                    }
                }
                catch (EmployeeIdException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }