예제 #1
0
        static void Main(string[] args)
        {
            var departments = new DepartmentCollection();

            departments.Add("万文峰", new Employee {
                Name = "万"
            })
            .Add("万文峰", new Employee {
                Name = "文"
            })
            .Add("万文峰", new Employee {
                Name = "峰"
            });
            departments.Add("龚岚", new Employee {
                Name = "龚"
            })
            .Add("龚岚", new Employee {
                Name = "岚"
            })
            .Add("龚岚", new Employee {
                Name = "gong"
            });
            foreach (var d in departments)
            {
                Console.WriteLine(d.Key);
                foreach (var v in d.Value)
                {
                    Console.WriteLine("\t" + v.Name);
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var departments = new DepartmentCollection();

            departments.Add("Engineering", new Employee("Bob"))
            .Add("Engineering", new Employee("Scott"))
            .Add("Engineering", new Employee("Joy"))
            .Add("Engineering", new Employee("Bob"));

            departments.Add("Sales", new Employee("Alex"))
            .Add("Sales", new Employee("Sarah"));

            departments.Add("Sales", new Employee("Ryan"));

            foreach (var department in departments)
            {
                Console.WriteLine(department.Key);
                foreach (var employee in department.Value)
                {
                    Console.WriteLine("\t" + employee.Name);
                }
            }

            // Console.WriteLine("----LinkedList----");

            // LinkedList<int> list = new LinkedList<int>();
            // list.AddFirst(2);
            // list.AddFirst(3);

            // var first = list.First;
            // list.AddAfter(first, 5);
            // list.AddBefore(first, 10);

            // var node = list.First;
            // while( node != null)
            // {
            //     Console.WriteLine(node.Value);
            //     node = node.Next;
            // }

            // Console.WriteLine("----HashSet----");

            // HashSet<Employee> set = new HashSet<Employee>();
            // var employee1 = new Employee("Scott");
            // set.Add(employee1);
            // set.Add(employee1);

            // foreach(var item in set)
            // {
            //     Console.WriteLine(item.Name);
            // }

            // Console.WriteLine("----Queue----");

            // Queue<Employee> queue = new Queue<Employee>();
            // queue.Enqueue(new Employee("Alex"));
            // queue.Enqueue(new Employee("Dani"));
            // queue.Enqueue(new Employee("Chris"));

            // while (queue.Count > 0)
            // {
            //     var employee = queue.Dequeue();
            //     Console.WriteLine(employee.Name);
            // }

            // Console.WriteLine("----Stack----");

            // Stack<Employee> stack = new Stack<Employee>();
            // stack.Push(new Employee("Alex"));
            // stack.Push(new Employee("Dani"));
            // stack.Push(new Employee("Chris"));

            // while (stack.Count > 0)
            // {
            //     var employee2 = stack.Pop();
            //     Console.WriteLine(employee2.Name);
            // }
        }