0

I have a list array named "list". I need to convert this list into a hex string. I tried the code below but it hasn't worked.

    var  list = objIPLayer.Udp.Payload.ToList();
    string hex = BitConverter.ToString(list); 

I got this error:

The best overloaded method match for 'System.BitConverter.ToString(byte[])' has some invalid arguments** when executed the following code.

string hex = BitConverter.ToString(list);

Is there any method to do this?

Leigh
  • 28,765
  • 10
  • 55
  • 103
Mask
  • 647
  • 2
  • 9
  • 21
  • Its type is byte. **List**. – Mask Jan 12 '13 at 06:34
  • I got this error **The best overloaded method match for 'System.BitConverter.ToString(byte[])' has some invalid arguments** when executed the following code. **string hex = BitConverter.ToString(list);** – Mask Jan 12 '13 at 06:35

2 Answers2

0

BitConverter.ToString(byte[]) Expects byte [] not IEnumerable<byte> or List<byte>.

Try following

var  list = objIPLayer.Udp.Payload.ToArray();
string hex = BitConverter.ToString(list);
Tilak
  • 30,108
  • 19
  • 83
  • 131
0

Convert the list to an array first:

string hex = BitConverter.ToString(list.ToArray());
thudbutt
  • 1,481
  • 1
  • 19
  • 32