Store name + number and sort in size order based on the numbers

后端 未结 5 1595
梦如初夏
梦如初夏 2021-01-24 07:20

Doing a college project and I\'m a bit stuck..

Basically, I need to take the string input for an employee name and an integer input for the amount of properties they sol

5条回答
  •  生来不讨喜
    2021-01-24 08:13

    you can use the dictionary to implementing this senario

     Dictionary users = new Dictionary();
    
                for (int i = 0; i < 2; i++)
                {
                    Console.WriteLine("Please enter the employee name: ");
                    string name = Console.ReadLine();
                    Console.WriteLine("Please enter the number of Properties Sold: ");
                    int number = int.Parse(Console.ReadLine());
                    users.Add(name, number);
                 }
    
                var data = users.OrderByDescending(a => a.Value).ToList();
    
                foreach (var i in data)
                {
    
                    Console.WriteLine(i.Key+" "+i.Value);
                }
    

提交回复
热议问题