Vidar Vidar - 1 year ago 92
C# Question

What is the best way to store pairs of strings, make an object or use a class in .NET?

Don't know whether I'm having a "thick day" - but I just wondered what is the best route here.


I have a list of fields and I want to store alias names with them (I'm using .NET 2.0 BTW) e.g.

enter image description here

So its essentially a pair of strings:


COMMUNITY, Community


... and I'm thinking it seems overboard all the time to keep creating objects for things like this, so should I create a StringDictionary and store the values that way, even though I would not use any of the functionality of the StringDictionary class and I'm not bothered about a key value pair association etc - I just want to keep a pair of strings essentially.

Any help/pointers would be great.

Answer Source

You can use the generic Dictionary<string, string> if your "Field Names" are unique.

Otherwise you could use the Lookup class if you don't mind duplicate keys.

I wouldn't worry too much about whether you use the full functionality of those classes or not. I think the more important concern should be to write simple, easy to read & maintain code.