列表?字典?大批?
我试图想出一种非常简单的方法来为选项卡控件中的每个选项卡页存储布尔值。每个页面都有一个文本框,我想为每个页面存储一个 bool,因此如果 tabpage 1 已保存,则 bool1 设置为 true,否则设置为 false,依此类推。
然后,当他们关闭程序时,它将遍历所有选项卡页并查看每个选项卡页是否已保存。我需要能够创建某种可以搜索和操作的列表。
我以前曾为此使用过标签属性,但由于某种原因,它不再正常工作。
任何帮助建议将不胜感激:)
谢谢你,
bael。
i'm trying to come up with a very simple way to store a boolean value for each tabpage in a tabcontrol. each page has a textbox, and i would like to store a bool foreach page so if tabpage 1 has been saved, then bool1 is set to true, else false, and so on.
then when they go to close the program it will go over all the tabpages and see if each tabpage has been saved or not. i need to be able to create some sort of a list that i can search and manipulate.
i have previously used tag properties for this but for some reason that doesn't work PROPERLY anymore.
any help advice would be greatl;y appreciated :)
thank you,
bael.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
数组、列表或字典都不是用于跟踪一组对象的布尔状态的正确数据结构。执行此操作的结构是
HashSet
。T
要么在集合中,要么不在集合中。它优于
Dictionary
因为它实际上维护两个状态:对象是否在字典中,如果在,则其值是否为是真是假。它优于
List
有两个原因:它更快(尽管在您的情况下,这几乎肯定可以忽略不计),并且它并不意味着列表的顺序有一定的意义。它包含的对象,因为HashSet
中对象的顺序是任意的。Neither array, nor list, nor dictionary are the right data structure for tracking the boolean status of a set of objects. The structure that does this and nothing more is
HashSet<T>
. Either aT
is in the set, or it isn't.It's superior to a
Dictionary<T, bool>
because that actually maintains two states: whether the object is in the dictionary or not, and if it is, whether its value is true or false.It's superior to a
List<T>
for two reasons: It's faster (though in your case, that will almost certainly be negligible), and it doesn't imply that there's some meaning to the order of the objects it contains, since the order of objects in aHashSet<T>
is arbitrary.List
仅存储需要保存的标签页。如果为空,则无需保存任何内容。
List<TabPage>
Store only those tabpage(s) that needs to be saved. If empty, nothing needs to be saved.
例如,您可以使用
Dictionary
。在应用程序开始时:要更改 TabPage 的状态:
当应用程序完成时:
You can use for example a
Dictionary<TabPage,bool>
. At the start of your application:To change the state of a TabPage:
And when your application finishes:
如果您要进行迭代而不删除或添加元素,请使用数组。
如果您要迭代但添加和删除元素,请使用列表。
如果您使用字符串作为键,则使用字典。
与列表相比,字典具有非常快的查找性能和大量元素。
If you are iterating through without removing or adding elements use the array.
If you are iterating through but adding and removing elements use the List.
If you are using strings as keys then use the dictionary.
The dictionary has very fast lookup performance with a high number of elements compared to the List.