in my C# application i need to store huge amounts of constant strings in arrays, like one array for first names and one for last name and so on...
These strings never change so my question is how to store them ?
Make a static constant class with these arrays ?
Load them at runtime from somewhere?
Or any other solution...
PS: I don't really want external files so if i load them from somewhere they have to be included in the .exe
EDIT:// So i just make resource files with string[] arrays, alrigt :)
In cases like this i use resource files.
I create a resource file called Constants for example, and then i can call it from any where in my application.
Also in past i did it twice to create a class which contains all variables as 'const'.
public const string myVariable = "some static text";
but i felt its the wrong place to do that and started using resource files.
Update: The Question is telling that the fixed strings are in string[] array, which is a case i didn't remember i met, so don't know which way will be better for you in this case regarding performance and code maintainability.
Make a dedicated class in which you put the strings as readonly fields. When first requested you can put it in the Cache object so afterwards you can get them from there for fast retrieval.
Grz, Kris.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With