C# में BitConverter.ToString() मेथड का उपयोग बाइट्स के निर्दिष्ट ऐरे के प्रत्येक तत्व के संख्यात्मक मान को उसके समतुल्य हेक्साडेसिमल स्ट्रिंग प्रतिनिधित्व में बदलने के लिए किया जाता है।
सिंटैक्स
public static string ToString (byte[] val);
ऊपर, val बाइट ऐरे है।
उदाहरण
using System;
public class Demo {
public static void Main() {
byte[] arr = {0, 10, 2, 5, 32, 45};
int count = arr.Length;
Console.Write("बाइट ऐरे... ");
for (int i = 0; i < count; i++) {
Console.Write("\n" + arr[i]);
}
Console.WriteLine("\nबाइट ऐरे (स्ट्रिंग प्रतिनिधित्व) = {0} ",
BitConverter.ToString(arr));
}
}
आउटपुट
बाइट ऐरे... 0 10 2 5 32 45 बाइट ऐरे (स्ट्रिंग प्रतिनिधित्व) = 00-0A-02-05-20-2D
उदाहरण
using System;
public class Demo {
public static void Main() {
byte[] arr = { 0, 0, 7, 10, 18, 20, 25, 26, 32};
int count = arr.Length;
Console.Write("बाइट ऐरे... ");
for (int i = 0; i < count; i++) {
Console.Write("\n" + arr[i]);
}
Console.WriteLine("\nबाइट ऐरे (स्ट्रिंग प्रतिनिधित्व) = " + BitConverter.ToString(arr));
for (int i = 0; i < arr.Length - 1; i = i + 2) {
short res = BitConverter.ToInt16(arr, i);
Console.WriteLine("\nमान = " + arr[i]);
Console.WriteLine("परिणाम = " + res);
}
}
}
आउटपुट
बाइट ऐरे... 0 0 7 10 18 20 25 26 32 बाइट ऐरे (स्ट्रिंग प्रतिनिधित्व) = 00-00-07-0A-12-14-19-1A-20 मान = 0 परिणाम = 0 मान = 7 परिणाम = 2567 मान = 18 परिणाम = 5138 मान = 25 परिणाम = 6681