c#获取字符串长度、字节长度

 string sendData = sendTextBox.Text;    //复制发送数据
                //添加结束符
                sendData = sendData + "#$";
                //字符串发送
                if (hexadecimalSendCheckBox.IsChecked == false)
                {
                    //serial.Write(sendData);
                    byte[] arrData = System.Text.Encoding.Default.GetBytes(sendData);
                    socketUDP.SendTo(arrData,remoteEP);
                    //更新发送数据计数
                    sendBytesCount += (UInt32)sendData.Length;//获取字符串长度
                    //sendBytesCount += (UInt32)System.Text.Encoding.Default.GetBytes(sendData.ToCharArray()).Length;//获取字节长度
                    statusSendByteTextBlock.Text = sendBytesCount.ToString();

                }

你可能感兴趣的:(c#上位机开发)