我试图输入som飞行信息到词典C#控制台。 但我不知道如何将这些添加到我的Dictionary.I想要按航班号存储(我想将航班号作为KEY)。这里是我的课程和洞代码
添加到词典
public class Flight
{
public int FlightNr;
public string Destination;
}
int FlNr;
string FlDest;
List<Flight> flightList = new List<Flight>();
do
{
Console.Write("Enter flight nummer (only numbers) :");
FlNr = int.Parse(Console.ReadLine());
Console.Write("Enter destination :");
FlDest = Console.ReadLine();
flightList.Add(new Flight() { FlightNr = FlNr, Destination = FlDest });
} while (FlNr != 0);
// create Dictionary
Dictionary<int, Flight> dictioneryFlight = new Dictionary<int, Flight>();
// My question is How to add those flights in my Dictionary ?
dictioneryFlight.Add(I don't know what to input here);
或者是我的其他代码有问题吗?我错过了什么?先谢谢你!
。
你要使用的关键是什么字典?航班号?你需要指定。 – itsme86
@ itsme86是航班号,谢谢 –