0
Console.WriteLine
の番号が付いた辞書をどのように把握しようとしていますか。辞書の番号付きメニュー<>
CollectionManager shoppers =
new CollectionManager
{
Carts = new List<Inventory>(),
Dictionary = new Dictionary<string, List<Inventory>>()
};
そして、私が試してみました方法:これは、一種の作品
public static void DisplayShoppers(CollectionManager shoppers)
{
List<string> temp =new List<string>();
temp = shoppers.Dictionary.Keys.ToList();
for (int i = 0; i < temp.Count; i++)
{
Console.WriteLine((i + 1) + ". Name: " + temp[i]);
}
Console.WriteLine("Pick a card to Shopper: ");
int index = int.Parse(Console.ReadLine());
if (index > temp.Count || index < 1)
{
return ;
}
temp.RemoveAt(index - 1);
}
?辞書の各エントリの最初の文字を印刷するだけです。
switch (choice)
{
case 1:
Customers temp = CreateCustomers();
shoppers.Dictionary.Add(temp.ToString(), new List<Inventory>());
break;
case 2:
DisplayShoppers(shoppers);
break;
}
//method for creating customer
static Customers CreateCustomers()
{
Console.WriteLine("Create a Customer.");
string name = Console.ReadLine();
return new Customers {Name = name};
}
( 'temp'変数からの)項目を表示するコードはok(キーとして保存された文字列全体が表示されるはずです)のようです。それは、辞書のキーがただ一つの文字であるかもしれないことを示唆している。辞書に項目を追加するコードを確認してください。 –
辞書に値を追加するコードを表示できますか? – FCin
メソッドとメソッド呼び出しを追加しました。 –