Reputation: 2457
I use a List<string>
to which I add a few hundred thousand of random strings to be then used within my program.
I need this list quite at the beginning of the program and the random strings which it uses are saved in a textfile. At the moment the first thing the program does after loading, is adding all the items to the list. However, since the list is exactly the same every single time I wonder if there is a way to save it somehow internally so the list can just be directly used and does not need to be expanded on every single startup.
Upvotes: 0
Views: 212
Reputation: 1038770
The list needs to be persisted somewhere otherwise when the application shuts down you will loose all values. When the application shuts down, the memory that was used to store this list is returned back to the Operating System. So, no, there's no other way to have the list in memory when the application starts without reading it from somewhere - whether this would be a file, database or some other storage you need to load it from there or regenerate it from scratch.
If you do not care about the file format in which the list is stored you could use a BinaryFormatter for faster serialization and deserialization compared to XML, JSON and other formats.
Upvotes: 2