0

I'm currently working in a java to c# conversion project. In one part I got this Java code snippet.

public CustomType someMethod(Message msg) throws IOException 
{
    byte[] data = msg.toString().getBytes();
}

to my understanding, data contains the byte representation of the string msg.toString()

But when I try to write it in C# like following format, i get errors.

public CustomType someMethod(Message msg)
{
    try
    {
        byte[] data= byte.Parse(msg.ToString());
    }
    catch(IOException e)
    {
        throw e;
    }
}

how can I solve this problem?

4
Contributors
4
Replies
23
Views
4 Years
Discussion Span
Last Post by mesbahuk
1

Something like this?

byte[] data = Encoding.Default.GetBytes(msg.ToString());

You also need to include this namespace: System.Text

Edited by TheApex

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.