2013-01-12 30 views
0

我有一個名爲「list」的列表數組。我需要將此列表轉換爲十六進制字符串。我嘗試了下面的代碼,但它沒有奏效。如何將列表數組轉換爲C#中的Hexstring?

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

我得到這個錯誤:

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

string hex = BitConverter.ToString(list); 

有沒有方法做到這一點?

+0

什麼類型是你的名單? –

+0

它的類型是字節。 **列表 **。 – Mask

+0

我得到這個錯誤**當執行下面的代碼時,'System.BitConverter.ToString(byte [])'的最佳重載方法匹配有一些無效參數**。 **字符串十六進制= BitConverter.ToString(列表); ** – Mask

回答

0

BitConverter.ToString(byte[])預計byte []不是IEnumerable<byte>List<byte>

嘗試以下

var list = objIPLayer.Udp.Payload.ToArray(); 
string hex = BitConverter.ToString(list); 
+0

是的它的工作。我需要在該字符串中替換「 - 」。謝謝。 – Mask

0

轉換列表中的數組第一:

string hex = BitConverter.ToString(list.ToArray()); 
相關問題