我有一個汽車類,它有獲取和設定方法。它包括匯入車輛資訊和匯出該車輛資訊。我使用字典來存盤所有車輛資訊。我在串列類中創建了一個汽車輸入函式:
Dictionary<string, Car> Dic = new Dictionary<string, Car>();
public void InputCar()
{
Car car = new Car();
car.Input();
Dic.Add(car.BienSo1, car);
}
現在我想在我輸入的任何位置插入以將新車資訊放入字典中,我該怎么做?
例子:
Number Plate : 21112
Name Car : Honda
Number Plate : 33333
Name Car : Suzu
Insert at position 1 into the dictionary
Enter to put new car information
Number Plate : 21112
Name Car : Honda
Number Plate : 11111
Name Car : Toyota
Number Plate : 33333
Name Car : Suzuki
uj5u.com熱心網友回復:
嘗試查看OrderedDictionary而不是普通字典。OrderedDictionary.Insert將允許您指定插入鍵的索引。普通字典使用鍵而不是索引,因此這是不可能的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/429164.html
標籤:C#
上一篇:ASP.NETMVC/JavaScript只有1個添加的輸入被插入到db
下一篇:如何在python中多次回圈
