数据结构来消除c#中的多个哈希表(data structure to eliminate multiple hashtables in c#)

编程入门 行业动态 更新时间:2024-10-25 16:27:29
数据结构来消除c#中的多个哈希表(data structure to eliminate multiple hashtables in c#)

我正在开发一个应用程序,在该应用程序中,我在运行时添加了控件,并跟踪这些控件,我正在维护单独的哈希表,以便以后可以轻松地完成我想要的任何操作。 但是我有大约6个哈希表,并且保持这些有点复杂。 所以我想知道我是否可以将所有这些控件都放到一个数据结构中,但是我应该很容易地识别它们,就像我在散列表中一样。 基本上我想要的是散列表的扩展版本,我可以在一个键上添加多个值。 例如我现在拥有的是什么

hashtable addButtons = new hashtable(); hashtable remButtons = new hashtable(); addButtons.add(name,b); remButtons.add(name,r);

如果我可以做类似的事情,现在会很酷

addButtons.add(name=>(b,r,etc,etc));

然后像哈希表一样得到它

addButtons[name][1]

任何人都可以告诉我,如果这样的事情可能在C#中。

i am developing an application in which i add controls during runtime and to keep track of these controls i am maintaing separate hashtables so that it will be easy for me to do what ever i want with them later. But I am having around 6 hashtables and maintaining these is a little complex. So i was wondering whether i can have all these controls in to one data structure but it should be easy for me to identify them just like i do in hashtable. Basically what i want is an extended version of hashtable where i can add multiple values to one key. For example what i have now is

hashtable addButtons = new hashtable(); hashtable remButtons = new hashtable(); addButtons.add(name,b); remButtons.add(name,r);

Now it would be cool if i can do something like

addButtons.add(name=>(b,r,etc,etc));

and then get any of it just like in hashtable like

addButtons[name][1]

Can any one tell me if something like this is possible in c#.

最满意答案

我会有一个班级代表6件事...

public class SomeType { // RENAME ME public int AddButton {get;set;} public string RemoveButton {get;set;} public DateTime Some {get;set;} public float Other {get;set;} public decimal Names {get;set;} public bool Here {get;set;} } // ^^ names and types above just made up; FIX ME!

和一个Dictionary<string,SomeType> - 然后你可以:

yourField.Add(name, new SomeType { AddButton = ..., ..., Here = ... });

var remButton = yourField[name].RemoveButton;

I would have a class representing the 6 things...

public class SomeType { // RENAME ME public int AddButton {get;set;} public string RemoveButton {get;set;} public DateTime Some {get;set;} public float Other {get;set;} public decimal Names {get;set;} public bool Here {get;set;} } // ^^ names and types above just made up; FIX ME!

and a Dictionary<string,SomeType> - then you can:

yourField.Add(name, new SomeType { AddButton = ..., ..., Here = ... });

and

var remButton = yourField[name].RemoveButton;

更多推荐

本文发布于:2023-07-22 12:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219972.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   数据结构   哈希表   data   hashtables

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!