C# 将IPv4地址从字节数组复制到字符串

C# 将IPv4地址从字节数组复制到字符串,c#,bytearray,ip-address,C#,Bytearray,Ip Address,我有一个ipv4地址存储在字节数组中。在索引n和索引n+3之前,每个索引占用4个字节 (index) n n+1 n+2 n+3 [..] [..] [..] [ 1st byte ][ 2nd ] [ 3rd ] [ 4th ] [..] [..] 如何将此结构复制到字符串。我希望接收像“192.168.0.1”这样的字符串,而 最后,问题解决了,解决方案是: string str = recCommand

我有一个ipv4地址存储在字节数组中。在索引
n
和索引
n+3
之前,每个索引占用4个字节

(index)              n       n+1     n+2    n+3                 
[..] [..] [..] [ 1st byte ][ 2nd ] [ 3rd ] [ 4th ] [..] [..]
如何将此结构复制到字符串。我希望接收像“192.168.0.1”这样的字符串,而

最后,问题解决了,解决方案是:

string str = recCommand.parameters[10] + "." + recCommand.parameters[11] +
 "." +   recCommand.parameters[12] + "." + recCommand.parameters[13];
像这样的

        byte[] some = { 192, 168, 0, 1 };
        String ip = "" + some[0] + "." + some[1] + "." + some[2] + "." + some[3];
        Console.WriteLine("ip=" + ip  );

那么,在第一个八位字节之前,字节[]数组中存储了什么呢?如果它为null,那么您只需通过数组检查If!null并将结果存储在字符串中。。。。循环字节[]数组..检查!空…+=一串对不起,这篇文章太粗糙了。有一部分查询命令是通过TCP接收的,它不是一个null@vard-你到底试过什么?只需将索引
n
通过
n+3
转换为一个字符串,并将它们组合起来即可。在你们真正展示你们的努力之前,我必须否决这个问题。@Ramhound是的,我已经尝试过了。这是一段真正的代码:
string str=recCommand.parameters[10]+“+recCommand.parameters[11]+“+recCommand.parameters[12]+”+recCommand.parameters[13]
@vard-您需要用您尝试过的内容更新问题。是的,谢谢,安妮的评论也有相同的建议,但不幸的是作者删除了它。很好,谢谢。可以简化为string.Format(“{0}.{1}.{2}.{3}”,有些)
        byte[] some = { 192, 168, 0, 1 };
        String ip = "" + some[0] + "." + some[1] + "." + some[2] + "." + some[3];
        Console.WriteLine("ip=" + ip  );