C#BitConverter.ToChar()メソッド
C#のBitConverter.ToChar()メソッドは、バイト配列の指定された位置にある2バイトから変換された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 = ꀒ
-
C#のConvert.ToCharメソッド
Convert.ToCharメソッドは、指定された値をUnicode整数に変換するために使用されます。 sbyte変数を宣言しました。 sbyte byteVal = 200; 次に、Convert.ToChar()メソッドを使用して、sbyte値をUnicode整数に変換します。 charVal = Convert.ToChar(b); 別の例を見てみましょう。 例 using System; public class Demo { public static void Main() { sbyte[] byteVal
-
C#の集計メソッド
C#でAggregateメソッドを使用して、Sum、Min、Max、Averageなどの数学演算を実行します。 Aggregateメソッドを使用して配列要素を乗算する例を見てみましょう。 これが私たちの配列です- int[] arr = { 10, 15, 20 }; ここで、Aggregate()メソッドを使用します- arr.Aggregate((x, y) => x * y); これが完全なコードです- 例 using System; using System.Linq; using System.IO; public class Demo { p