0

I'm trying to create a simple Hex Editor with C#. For this I'm writing the file into an byte-array, which works fine. But as soon as I put out the bytes to a Textbox in form of a string, the overall performance of the program becomes pretty bad. For example a 190kb file takes about 40 seconds, till it is displayed in the textbox. While that the program is not responding.

The function:

void open() { fullstring = ""; OpenFileDialog op = new OpenFileDialog(); op.ShowDialog(); file = op.FileName; byte[] fileB = File.ReadAllBytes(file); long b = fileB.Length; for (int i = 0; i < fileB.Length; i++) { fullstring = fullstring + fileB[i].ToString("X") + " "; } textBox9.Text = fullstring; } 

Is there a way to improve performance in this function?

1

1 Answer 1

0

Take a look at this post How do you convert Byte Array to Hexadecimal String, and vice versa? You can use the code there to output your byte array to text file. One problem you have in your code is that you are using String concatenation instead of StringBuilder. It is better to use StringBuilder otherwise the performance degrades.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.