Store Key / Value Pair
-
Imagine a class with the following properties Shape //differnt shapes Colour //different colours Fill //yes or no Border //yes or no Etc etc – there could lots of different ones, maybe even a 100 Each value associated with the above properties has to have a key/value pair (eg [1] [Red]), the number will be used to submit to a 3rd party software and the text to give the option to the user. Now how should I store them? I could use a hashtable to store the options as DictonaryPairs, and then the data type of each property could be a DictonaryPair. This works in theory, but in practice it means the fill could be given [1] [Red] instead on [0] [No] So I then thought I could inherit from DictonaryPair to make ShapeDictonaryPair ColourDictonaryPair BoolDictonaryPair And then the data types could be the following ShapeDictonaryPair Shape ColourDictonaryPair Colour BoolDictonaryPair Fill BoolDictonaryPair Border Which would work, but I will end up with loads of different Pair classes, which I think I will have to. So then, would you use Hashtables or generic lists? The items in the list or hashtable will need to end up in combo boxes, with the user seeing the value and then store the pair Or any other ideas Did that make sense :sigh:
-
Imagine a class with the following properties Shape //differnt shapes Colour //different colours Fill //yes or no Border //yes or no Etc etc – there could lots of different ones, maybe even a 100 Each value associated with the above properties has to have a key/value pair (eg [1] [Red]), the number will be used to submit to a 3rd party software and the text to give the option to the user. Now how should I store them? I could use a hashtable to store the options as DictonaryPairs, and then the data type of each property could be a DictonaryPair. This works in theory, but in practice it means the fill could be given [1] [Red] instead on [0] [No] So I then thought I could inherit from DictonaryPair to make ShapeDictonaryPair ColourDictonaryPair BoolDictonaryPair And then the data types could be the following ShapeDictonaryPair Shape ColourDictonaryPair Colour BoolDictonaryPair Fill BoolDictonaryPair Border Which would work, but I will end up with loads of different Pair classes, which I think I will have to. So then, would you use Hashtables or generic lists? The items in the list or hashtable will need to end up in combo boxes, with the user seeing the value and then store the pair Or any other ideas Did that make sense :sigh:
You don't really need to create that many pairs - use the generic KeyValuePair and Dictionary classes instead. like
Dictionary <int, Color > dict = new Dictionary <int, Color >
dict.Add(1, Color.Red);
dict.Add(2, Fill.All); // Won't compile.Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
You don't really need to create that many pairs - use the generic KeyValuePair and Dictionary classes instead. like
Dictionary <int, Color > dict = new Dictionary <int, Color >
dict.Add(1, Color.Red);
dict.Add(2, Fill.All); // Won't compile.Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
Looks good, but it wont work for my needs (my fault for not being detailed enough in the first post, sorry) The value must be a string, so they will all be Dictionary <int, string > The 1st post was only trying to give an example, and in the real app, the values will be things that are not represented by .net classes (I could make classes for each type, but again that means loads of classes)