列表?字典?大批?

发布于 2024-08-13 00:56:48 字数 279 浏览 3 评论 0原文

我试图想出一种非常简单的方法来为选项卡控件中的每个选项卡页存储布尔值。每个页面都有一个文本框,我想为每个页面存储一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

飘然心甜 2024-08-20 00:56:48

数组、列表或字典都不是用于跟踪一组对象的布尔状态的正确数据结构。执行此操作的结构是 HashSetT 要么在集合中,要么不在集合中。

它优于 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 a T 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 a HashSet<T> is arbitrary.

╰沐子 2024-08-20 00:56:48

List

仅存储需要保存的标签页。如果为空,则无需保存任何内容。

List<TabPage>

Store only those tabpage(s) that needs to be saved. If empty, nothing needs to be saved.

倥絔 2024-08-20 00:56:48

例如,您可以使用 Dictionary。在应用程序开始时:

var pageStates=new Dictionary<TabPage,bool>();

foreach(var page in tabControl.TabPages) {
    pageStates.Add(page, false);
}

要更改 TabPage 的状态:

pageStates[page]=true;

当应用程序完成时:

foreach(var page in TabControl.TabPages) {
    if(pageStates[page]) {
        //The page is saved
    }
}

You can use for example a Dictionary<TabPage,bool>. At the start of your application:

var pageStates=new Dictionary<TabPage,bool>();

foreach(var page in tabControl.TabPages) {
    pageStates.Add(page, false);
}

To change the state of a TabPage:

pageStates[page]=true;

And when your application finishes:

foreach(var page in TabControl.TabPages) {
    if(pageStates[page]) {
        //The page is saved
    }
}
清晰传感 2024-08-20 00:56:48

如果您要进行迭代而不删除或添加元素,请使用数组。

如果您要迭代但添加和删除元素,请使用列表。

如果您使用字符串作为键,则使用字典。

与列表相比,字典具有非常快的查找性能和大量元素。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文