【发布时间】:2016-08-24 20:03:55
【问题描述】:
我正在尝试将 som 航班信息输入到 Dictionary C# 控制台。
但我不知道如何将它们添加到我的字典中。我想按航班号存储(我希望航班号作为 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 是的航班号,谢谢
标签: c# dictionary