Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of getBytes() in Java to C#

Tags:

java

c#

asp.net

I want to convert a class which is in Java to C#, most of the changes are done already but I have this part which I am not really sure about. I want to convert this line of code:

byte[] arrayOfByte1 = paramString.getBytes();

I have tried this:

byte[] arrayOfByte1 = BitConverter.GetBytes(paramString);

But it does not work as GetBytes() is expecting a double. I am not sure if just converting it to a double would solve the issue, so I wanted to ask about it here.

like image 797
Ryan S Avatar asked Sep 06 '25 02:09

Ryan S


2 Answers

Depending on your encoding you do this similar to the following:

byte[] arrayOfByte1 = Encoding.UTF8.GetBytes (paramString);

For reference see http://msdn.microsoft.com/en-us/library/ds4kkd55.aspx

like image 53
Yahia Avatar answered Sep 07 '25 19:09

Yahia


It could be:

Bytes[] byteAray = Encoding.GetBytes(paramString);

From Microsoft site

like image 35
Steve Avatar answered Sep 07 '25 21:09

Steve