C# BitConverter.ToChar() 方法使用示例
C#中的BitConverter.ToChar()方法用于返回从字节数组中指定位置的两个字节转换而来的Unicode字符。
语法
public static char ToChar (byte[] value, int begnIndex);
在上面,val是字节数组,而begnIndex是val中的开始位置。
示例
using System;
public class Demo {
public static void Main() {
byte[] arr = { 0, 20, 50, 65 };
Console.WriteLine("Array = {0} ",
BitConverter.ToString(arr));
for (int i = 1; i < arr.Length - 1; i = i + 2) {
char values = BitConverter.ToChar(arr, i);
Console.WriteLine("Value = "+arr[i]);
Console.WriteLine("Result = "+values);
}
}
}输出结果
Array = 00-14-32-41 Value = 20 Result = ㈔
示例
using System;
public class Demo {
public static void Main() {
byte[] arr = { 50, 13, 23, 18, 160 };
Console.WriteLine("Array = {0} ",
BitConverter.ToString(arr));
for (int i = 1; i < arr.Length - 1; i = i + 2) {
char values = BitConverter.ToChar(arr, i);
Console.WriteLine("Value = "+arr[i]);
Console.WriteLine("Result = "+values);
}
}
}输出结果
Array = 32-0D-17-12-A0 Value = 13 Result = ᜍ Value = 18 Result = ꀒ
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短