欲在C#种实现以下雷同功能:VC++得实现:
//报头
*(unsigned int*)(buf)=htonl(m_nSeq++);        //包序号
*(unsigned short*)(buf+4)=htons(TYPE_DZJP);   //业务类型
*(unsigned int*)(buf+6)=htonl(COM_LOGIN);     //命令类型
*(unsigned int*)(buf+10)=htonl(20);           //包体长度
*(unsigned int*)(buf+14)=htonl(777);          //银行IDC#得实现:
private  byte[]  buf;  //整个包得数据
buf=new byte[58];
buf=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(m_nSeq++));       //包序号4字节整数
buf[4]=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ));   //TYPE_YQDZ为2字节短整数这里不行,说是:
D:\Work\YQDZ\YQDZ\CCSock.cs(181): 无法将类型“byte[]”隐式转换为“byte”
怎么写啊??谢谢

解决方案 »

  1.   

    buf[4]=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ));   
    ----
    这个得到的是一个byte么?
    那么应该
    byte []temp=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ));   
    buf[4]=temp[0];
      

  2.   

    那么还需要写这样一行吗?
    buf[5]=temp[1];
      

  3.   

    这样做有用吗?
    如果用socket发,你的是上层的,等到了下曾照样再加上包头,你所谓的包头就成了数据信息了
      

  4.   

    ybzsu(弑君者): 您好!谢谢回复!!!我是采用Socket.Send来发送得,我没有弄懂你得意思啊,能详细一些么,我是菜鸟啊,救命!