Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most performant way to store large amounts of static strings

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 :)

like image 628
Chilln Avatar asked Jun 27 '10 15:06

Chilln


2 Answers

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.

like image 110
Amr Elgarhy Avatar answered Oct 26 '22 14:10

Amr Elgarhy


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.

like image 1
Kris van der Mast Avatar answered Oct 26 '22 14:10

Kris van der Mast