开发者

Most performant way to store large amounts of static strings

开发者 https://www.devze.com 2023-01-05 08:26 出处:网络
in my C开发者_Go百科# 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...

in my C开发者_Go百科# 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消