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");
}
}
}
}
}
Więc zachować uzyskiwanie „Przynajmniej jeden obiekt musi zaimplementować IComparable
At least one object must implement IComparable.
” podczas próby dodania drugiego gracza, pierwsza z nich działa, ale drugi nie. Muszę również używać SortedSet
, ponieważ jest to wymagane do pracy, to praca w szkole.
Błąd mówi dokładnie o tym, co powinieneś wiedzieć - Klasa 'Player' musi implementować interfejs" IComparable " –
Ten rodzaj błędu nie powinien istnieć, mamy niezawodny język z nielicznych powodów,' SortedSet 'powinien naprawdę mieć ograniczenie' T: IComparable ' –
Lukazoid