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
At least one object must implement IComparable.
」嘗試添加第二個球員的時候,第一個作品,但第二個沒有。 我也必須使用SortedSet
,因爲這是工作的要求,這是學校的工作。
錯誤告訴你到底需要知道什麼 - 你的Player類必須實現'IComparable'接口 –
這種錯誤不應該存在,我們有一個很好的類型安全語言,'SortedSet '應該真的有'T:IComparable ' –
Lukazoid