gpt4 book ai didi

c# - 如何在C#中对ResourceSet进行排序

转载 作者:行者123 更新时间:2023-11-30 19:50:53 24 4
gpt4 key购买 nike

我有一个名为 filetypes.resx 的资源文件。一些我想出如何将资源值绑定(bind)到下拉列表的方法,但我不知道如何对 ResourceSet 的值进行排序。

这是我到目前为止所做的,

文件类型.resx

  • 名称、值
  • A,1

  • B,2

  • C,3

绑定(bind)下拉列表的代码


DropDownList1.DataSource = Resources.FileTypes.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
DropDownList1.DataTextField = "Key";
DropDownList1.DataValueField = "Value";
DropDownList1.DataBind();

结果

 A C B
As you can see the result is not sorted. Please help me to solve this issue.

提前致谢:)

最佳答案

资源集有一个 IDictionaryEnumerator,所以我猜它的项目是 DictionaryEntry 类型,尝试像这样对数据源进行排序:

DropDownList1.DataSource = Resources.FileTypes.ResourceManager
.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true)
.OfType<DictionaryEntry>()
.OrderBy(i => i.Value);

嗯,我没有打开 visual studio 所以不要怪我,以防它不能立即工作:)

关于c# - 如何在C#中对ResourceSet进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1700240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com