19 hours ago, Alberth said:The problem, is that constructing a large string is quite deadly for performance, so that's what you should try to avoid. I don't know C#, so I used Java, which is close enough I hope to get the idea across:
byte[] bytes = {1, 2, 35, 8, 127}; // Open a text file for writing BufferedWriter handle = new BufferedWriter(new FileWriter("output.txt")); // Convert each byte to a string, and write the string for (byte b : bytes) { String s = Byte.toString(b); handle.write(s); handle.write(' '); // Add a space after each number. } handle.write('\n'); // Add a newline at the end. handle.close(); // Close the file.
The code constructs a string for each value, and writes that string to a text file. This code makes many small strings, which is not a major problem.
And the file looks like (as you'd expect)
1 2 35 8 127
I hope you can convert this to something C#-ish if you like the idea.
I would suggest doing this as well. I've worked on smaller projects and I had to export arrays to text files, and I just did it like this. It's very simple, fast, and easy to read. It's also easy to load back in without problems.
Take this as a learning experience, we can always learn new and better ways to do something.