0

I have a piece of text and I want to turn it into a byte array like this one:

        byte[,] input = new byte[4, 4] {
                                        { 0xd4, 0xe0, 0xb8, 0x1e },
                                        { 0xbf, 0xb4, 0x41, 0x27 },
                                        { 0x5d, 0x52, 0x11, 0x98 },
                                        { 0x30, 0xae, 0xf1, 0xe5 } 
                                       };

I'm giving the example because I have a method that can only take arguments as byte array (input is a valid argument) and I want to make sure I'm asking the right question.

1 Answer 1

6

You get bytes based on the encoding.

e.g.

Encoding.UTF8.GetBytes(string)
Sign up to request clarification or add additional context in comments.

5 Comments

I tried that, I get an The best overloaded method match for 'xxx.Program.function(byte[,])' has some invalid arguments error
also cannot convert byte [] to byte[,]
If this solution doesn't suffice, you need to specify how the two dimensional array correlates to the string better.
You can't magically create a 2 dimensional array. GetBytes returns a one-dimensional byte array. There is no magical method to return an array of arrays, you will have to then take those bytes and construct the specific layout you need.
As has been mentioned, a string will convert to a one dimensional array so for a better solution you will need to explain what is represented by the two-dimensional array.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.