Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

How to display a character of arrays in a textbox in Visual C#

This is related to a question I asked previously. I have an array of characters which I wish to assign to a textbox. To assign from the textbox to the array of characters, buffer, to the textbox, txtBox, I was given the following solution which works:

char[] buffer = System.Text.ASCIIEncoding.ASCII.GetChars(
                System.Text.ASCIIEncoding.ASCII.GetBytes(txtBox.Text));

Now, I need to do the opposite, but am not sure how to do it.

Would appreciate your help.
0
geeta_m9
Asked:
geeta_m9
2 Solutions
 
Gautham JanardhanCommented:
txtBox.Text = new string(buffer);
0
 
ImperdonatoCommented:
Use this:

foreach (char c in buffer ){
    txtBox.Text+= c.ToString();
}
0
 
ImperdonatoCommented:
gauthampjs' solution is much better. Please use that :)
0
 
Anurag ThakurCommented:
dosent this work
buffer.ToString ();
0
 
anarki_jimbelCommented:
Of course the first solution good and works.

The second one is much slower because of loop.

This one is as fast as the first one

TextBox1.Text = string.Concat(buffer);
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now