将Dictionary项添加到标签

本文关键字:标签 添加 Dictionary | 更新日期: 2023-09-27 17:53:09

我需要制作按钮来添加项目到标签这是字典条目

        var menu = new Dictionary<string, double>();
        //names of the items the user is buying and the count
        var items = new Dictionary<string, int>();
        menu.Add("soda", 0.5);
        menu.Add("water", 0.5);
        menu.Add("juice", 0.5);
        menu.Add("rice", 0.5);
        menu.Add("soup", 0.5);
        menu.Add("chicken", 0.5);
        menu.Add("steak", 0.5);
        menu.Add("beef", 0.5);

如何使按钮添加项到标签

将Dictionary项添加到标签

foreach (var m in menu)
{
    label1.Text += m.Key + ":" + m.Value.ToString() + Environment.NewLine;
}