转为String的方法,System.Text.UTF8Encoding.Unicode.GetString(buffer) To convert byte array to char value, we have static method of BitConverter class named ToChar (). This method takes byte array and starting index of the byte array from where conversion should start and returns a char value. To demonstrate make a window application. Drag one button on form. Now write the following code on Button click event: C# private void btn_convertchar_Click(object sender, EventArgs e) VB Private Sub btn_convertchar_Click(ByVal sender As Object, ByVal e As EventArgs) This is simple code to convert byte array to char value. Byte Array to Double: To convert byte array to double value, we have static method of BitConverter class named ToDouble (). This method takes byte array and starting index of the byte array from where conversion should start and returns a double value. To demonstrate make a window application. Drag one button on form. Now write the following code on Button click event: C# private void btn_double_Click(object sender, EventArgs e) VB Private Sub btn_double_Click(ByVal sender As Object, ByVal e As EventArgs) This is simple code to convert byte array to double value. Byte Array to Single: To convert byte array to single value, we have static method of BitConverter class named ToSingle (). This method takes byte array and starting index of the byte array from where conversion should start and returns a single value. To demonstrate make a window application. Drag one button on form. Now write the following code on Button click event: C# private void btn_single_Click(object sender, EventArgs e) VB Private Sub btn_single_Click(ByVal sender As Object, ByVal e As EventArgs) This is simple code to convert byte array to single value. Byte Array to Integer: To convert byte array to Integer value, we have static method of BitConverter class named ToInt32 (). This method takes byte array and starting index of the byte array from where conversion should start and returns an integer value. To demonstrate make a window application. Drag one button on form. Now write the following code on Button click event: C# private void btn_int_Click(object sender, EventArgs e) VB Private Sub btn_int_Click(ByVal sender As Object, ByVal e As EventArgs) This is simple code to convert byte array to integer value. Now write the following code on FORM LOAD event: C# private void Form1_Load(object sender, EventArgs e) VB Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) This simple article |
|