Choice of Data Structure
I need开发者_开发知识库 to have a list(array, ect) of objects that have a static values. What is the best way (more usefull) to organize such data structure on c#?
Now, I am able to do it using two ways: 1) Enumarations with an additional parameters: http://www.codeproject.com/KB/cs/stringenum.aspx 2) Create some class with needed fields and then create an array of different classes instances.
Please write what of methods is the best with comments why or provide other ideas how to do it
I think the data structure you adopt will be largely dependant on how you intend to use the static values.
If you are going to be doing a lot of comparisons, I would suggest an enumeration with custom attributes (as described in your link, but possibly taken further) to provide additional metadata. However, if the structure containing the static values is going to operate more like a series of choices (e.g. the Encoding class in System.Text) then a static class with fields marked as readonly would be a better option.
Tuples for objects with static values
Sounds like a classic example of a Dictionary, a simple Key-Value relationship http://dotnetperls.com/dictionary-keys
http://en.wikipedia.org/wiki/Associative_array
精彩评论