gpt4 book ai didi

c# - 是否可以对哈希表进行排序?

转载 作者:可可西里 更新时间:2023-11-01 07:50:07 27 4
gpt4 key购买 nike

我有一个返回 HashTable 的属性。我想在不重构我的属性(property)的情况下对其进行排序。 请注意:我不想返回另一种类型。代码:

    /// <summary>
/// All content containers.
/// </summary>
public Hashtable Containers
{
get
{
Hashtable tbl = new Hashtable();
foreach (Control ctrl in Form.Controls)
{
if (ctrl is PlaceHolder)
{
tbl.Add(ctrl.ID, ctrl);
}
// Also check for user controls with content placeholders.
else if (ctrl is UserControl)
{
foreach (Control ctrl2 in ctrl.Controls)
{
if (ctrl2 is PlaceHolder)
{
tbl.Add(ctrl2.ID, ctrl2);
}
}
}
}

return tbl;
}
}

最佳答案

哈希表通过将键映射到值来工作。此映射中隐含的概念是键未按任何特定顺序排序或存储。

但是,您可以看一下 SortedDictionary<K,V> .

关于c# - 是否可以对哈希表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/675759/

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