class AllocUser { //客户多于客服 public static void Test() { var customers = new List<Customer>() { new Customer() { Name = "A" }, new Customer() { Name = "B" }, new Customer() { Name = "C" }, new Customer() { Name = "D" }, new Customer() { Name = "E" }, new Customer() { Name = "F" }, new Customer() { Name = "G" }, }; var waiters = new List<Waiter>() { new Waiter() { Name = "1" }, new Waiter() { Name = "2" }, new Waiter() { Name = "3" }, }; Alloc(customers, waiters.OrderBy(p => Guid.NewGuid()).ToList()); } private static void Alloc(List<Customer> customers, List<Waiter> waiters) { for (int i = 0; i < customers.Count; i++) { var customer = customers[i]; if (i < waiters.Count) { customer.WaiterName = waiters[i].Name; } else { customer.WaiterName = waiters[(i % waiters.Count)].Name; } System.Console.WriteLine(customer.ToString()); } } } class Customer { public string Name { get; set; } public string WaiterName { get; set; } public override string ToString() { return string.Format("客户{0}被分配客服{1}", Name, WaiterName); } } class Waiter { public string Name { get; set; } }
原文地址:https://www.cnblogs.com/zhshlimi/p/8352829.html
时间: 2024-11-09 22:49:56