C# 字母化从resx文件C中提取的所有图像#

C# 字母化从resx文件C中提取的所有图像#,c#,resx,alphabetical,C#,Resx,Alphabetical,我有一个下拉组合框,可以更改图片框的图像。图像存储在一个resx文件中,该文件包含一个对图像进行计数的数组,因此,如果我决定添加更多图像,我只需更新组合框,然后将图像添加到resx文件中。我遇到的问题是,当我用组合框更新图像时,resx中的图像不是按字母顺序排列的,但它们确实会更改图片框中的图像 这是我的密码 ResourceSet cardResourceSet = Properties.Resources.ResourceManager.GetResourceSet(Cult

我有一个下拉组合框,可以更改图片框的图像。图像存储在一个resx文件中,该文件包含一个对图像进行计数的数组,因此,如果我决定添加更多图像,我只需更新组合框,然后将图像添加到resx文件中。我遇到的问题是,当我用组合框更新图像时,resx中的图像不是按字母顺序排列的,但它们确实会更改图片框中的图像

这是我的密码

        ResourceSet cardResourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

        attributes = new Image[cardCount];
        cardCount = 0;

        foreach (DictionaryEntry entry in cardResourceSet)
        {
            string resourceKey = (string)entry.Key;
            object resource = entry.Value;

            cardCount++;
        }

        attributes = new Image[cardCount];
        cardCount = 0;

        foreach (DictionaryEntry entry in cardResourceSet)
        {
            attributes[cardCount] = (Image)entry.Value;
            cardCount++;
        }

        if (attributeBox.SelectedIndex != -1)
        {
            this.cardImage.Image = attributes[attributeBox.SelectedIndex];
        }
如何让它按字母顺序对resx中的资源进行排序?

的返回类型实现了
IEnumerable
,因此您应该能够对其运行一些LINQ排序:

foreach (var entry in cardResourceSet.Cast<DictionaryEntry>().OrderBy(de => de.Key))
{

}
foreach(cardResourceSet.Cast().OrderBy(de=>de.Key)中的var条目)
{
}
由于您对它进行了两次迭代(尽管我不确定第一个for循环的点,除非有其他代码),您可能希望将排序结果分配给一个单独的变量:

var sortedCardResourceSet.Cast<DictionaryEntry>().OrderBy(de => de.Key).ToList();

foreach (var entry in sortedCardResourceSet)
{
    ...
}

...
var sortedCardResourceSet.Cast().OrderBy(de=>de.Key.ToList();
foreach(sortedCardResourceSet中的var条目)
{
...
}
...

您想按
排序吗?我花了一点时间就可以完成这项工作。谢谢