using System;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SortedSet<Player> PlayerList = new SortedSet<Player>();
while (true)
{
string Input;
Console.WriteLine("What would you like to do?");
Console.WriteLine("1. Create new player and score.");
Console.WriteLine("2. Display Highscores.");
Console.WriteLine("3. Write out to XML file.");
Console.Write("Input Number: ");
Input = Console.ReadLine();
if (Input == "1")
{
Player player = new Player();
string PlayerName;
string Score;
Console.WriteLine();
Console.WriteLine("-=CREATE NEW PLAYER=-");
Console.Write("Player name: ");
PlayerName = Console.ReadLine();
Console.Write("Player score: ");
Score = Console.ReadLine();
player.Name = PlayerName;
player.Score = Convert.ToInt32(Score);
//====================================
//ERROR OCCURS HERE
//====================================
PlayerList.Add(player);
Console.WriteLine("Player \"" + player.Name + "\" with the score of \"" + player.Score + "\" has been created successfully!" );
Console.WriteLine();
}
else
{
Console.WriteLine("INVALID INPUT");
}
}
}
}
}
所以我不断得到“
至少一个对象必须实现 IComparable。
“当尝试添加第二个玩家时,第一个有效,但第二个无效。我也必须使用SortedSet
,因为这是工作的要求,它是学校作业。