我試圖輸入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是航班號,謝謝 –