views:

46

answers:

3

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

A: 

Tuples for objects with static values

shk
It seems that Tuple Class is available from .NET 4.0 http://msdn.microsoft.com/en-us/library/system.tuple.aspx, but I am using 3.5
Anton
You can create your own Tupple class
shk
A: 

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

Sebastian Oliva
But there will be a lot of parasmeters, more than five. So using just a Dictionary is note usefull. May be I need to use Dictionary of custom class instances.
Anton
A: 

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.

Bradley Smith
Yes, there will be a lot of comparisions. First time I stopped on enumerations, but when there are a lot of custom attributes, code is bad readable and redundant(for all attributes - their own methods)
Anton