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,605
  • 10
  • 52
  • 98
Mask
  • 637
  • 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
  • 28,854
  • 17
  • 79
  • 129
0

Convert the list to an array first:

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