我正在开发一个应用程序,在该应用程序中,我在运行时添加了控件,并跟踪这些控件,我正在维护单独的哈希表,以便以后可以轻松地完成我想要的任何操作。 但是我有大约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;更多推荐
发布评论