1

In my application i write the code like this

byte[] byt = new byte[Convert.ToSbyte(textbox1.Text)];

it is giving the error that input string was not in a correct format.

1
  • 2
    it couldn't be much more specific , now could it? Commented May 20, 2010 at 11:49

4 Answers 4

3

This is a wild guess, but are you trying to convert the contents of the text box into a byte array? If so, you can do it like this:

byte[] byt = Encoding.UTF8.GetBytes(textbox1.Text);
Sign up to request clarification or add additional context in comments.

Comments

1

The text in textbox1 is not a valid numeral for a signed byte.

Does it have spaces? Letters? ...?

4 Comments

ya it text box contain letter
@Surya: Then how do you expect it to give you a valid number?
actually it is encrypting the text what we enter in the textbox
it is a SHA256 which convert the encrypted form
1

What are you trying to do? The new byte[num] creates an array of 'num' bytes, where 'num' is usually an integer. All bytes in the array are then 0.

It doesn't create a filled array, as I suspect you may be trying to do.

What are the contents of that textbox1.Text that gave the error?

Comments

0

what you want in fact is this

 // C# to convert a string to a byte array.
 public static byte[] StrToByteArray(string str)
 {
     System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
     return encoding.GetBytes(str);
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.