我可以使用comboBox中的所有项目遍历字典吗?

时间:2017-06-11 04:17:34

标签: c#

我之前尝试过问这个问题,但没有解释得好。我会再试一次,我有一个字典,可以获取和设置图像的字符串,并列出获取字符串。字典项存储在listBox中,当我双击它设置的项目到另一个comboBox时。我想单击一个将遍历字典的按钮,如果它们匹配字典中的任何内容,它将存储在listView中。我不想要图像,只需要字符串名称和价格,这里是类和字典:

$resultLoad = getUserDetails($db,"photo","user_details",$_SESSION['theUserskey']);

$photosName = $resultLoad['photo'];
$file = 'photos/' . $photosName;

// Check mime type
$mime = mime_content_type($file);

$validMimes = ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml'];

// Refuse to serve invalid files
if (!in_array($mime, $validMimes)) {
    die('Invalid file type');
}

header('Content-Type:' . $mime);
header('Content-Length: ' . filesize($file));
readfile($file);
exit();

你们觉得我应该上新课吗?我在其他许多人中尝试过这个:

    class BookTitle
    {
        public string ImageTitle { get; set; }
        public List<string> Prices { get; }

        public BookTitle(string imageTitle, params string[] prices)
        {
            ImageTitle = imageTitle;
            Prices = new List<string>(prices.Length);
            Prices.AddRange(prices);
        }
    }

    private Dictionary<string, BookTitle> prices = new Dictionary<string, BookTitle>
    {
        { "Visual Basic", new BookTitle("vb.png", "$55") },
        { "Java", new BookTitle("java.png", "$45") },
        { "C#", new BookTitle("c#.png", "$75") },
        { "LAN Networks", new BookTitle("lan.png", "$68") },
        { "Windows Networking", new BookTitle("windows.png", "$49") },
        { "More About Networking", new BookTitle("more.png", "$54") },
        { "Web Programming", new BookTitle("web.png", "$67") },
        { "JavaScript", new BookTitle("javascript.png", "$64") },
        { "ASP", new BookTitle("asp.png", "$50") }
    };

2 个答案:

答案 0 :(得分:1)

你可以这样做,

def calculate(param: Similarity) = {
    println("hi")
  }

答案 1 :(得分:1)

@Sajeetharan我会接受你的回答,因为它非常有帮助,让我走上了正确的轨道。我最终做到了这一点:

    private void finalizeButton_Click(object sender, EventArgs e)
    {
        foreach (var comboItem in cartComboBox.Items)
        {
            if (prices.Keys.Contains(comboItem.ToString()))
            {
                BookTitle bt = prices[comboItem.ToString()];
                ListViewItem list = cartListView.Items.Add(comboItem.ToString());
                foreach (var p in bt.Prices)
                {
                    list.SubItems.Add(p);
                }
            }
        }
    }