কম্পিউটার টিউটোরিয়াল

C# BitConverter.ToUInt16() মেথড

C#-এ BitConverter.ToUInt16() মেথড একটি বাইট অ্যারেতে নির্দিষ্ট অবস্থানের দুটি বাইট থেকে 16-বিট অনসাইনড ইন্টিজার (ushort) রূপান্তর করে।

সিনট্যাক্স

public static ushort ToUInt16 (byte[] val, int beginIndex);

এখানে, val হলো বাইট অ্যারে, আর beginIndex হলো অ্যারেতে শুরুয়ার ইনডেক্স।

উদাহরণ ১

using System;

public class Demo {
    public static void Main() {
        byte[] arr = { 10, 20, 30, 40, 50 };
        int count = arr.Length;
        Console.Write("Byte Array... ");
        for (int i = 0; i < count; i++) {
            Console.Write("\n" + arr[i]);
        }
        Console.WriteLine("\n\nByte Array (String representation) = {0} ",
            BitConverter.ToString(arr));
        for (int i = 1; i < arr.Length - 1; i = i + 2) {
            ushort res = BitConverter.ToUInt16(arr, i);
            Console.WriteLine("\nValue = " + arr[i]);
            Console.WriteLine("Result = " + res);
        }
    }
}

আউটপুট

Byte Array...
10
20
30
40
50
Byte Array (String representation) = 0A-14-1E-28-32
Value = 20
Result = 7700
Value = 40
Result = 12840

উদাহরণ ২

using System;

public class Demo {
    public static void Main() {
        byte[] arr = { 0, 0, 1, 3, 5, 7, 10, 16, 20, 34, 42, 55, 66, 75 };
        int count = arr.Length;
        Console.Write("Byte Array... ");
        for (int i = 0; i < count; i++) {
            Console.Write("\n" + arr[i]);
        }
        Console.WriteLine("\n\nByte Array (String representation) = {0} ",
            BitConverter.ToString(arr));
        for (int i = 1; i < arr.Length - 1; i = i + 2) {
            ushort res = BitConverter.ToUInt16(arr, i);
            Console.WriteLine("\nValue = " + arr[i]);
            Console.WriteLine("Result = " + res);
        }
    }
}

আউটপুট

Byte Array...
0
0
1
3
5
7
10
16
20
34
42
55
66
75
Byte Array (String representation) = 00-00-01-03-05-07-0A-10-14-22-2A-37-42-4B
Value = 0
Result = 256
Value = 3
Result = 1283
Value = 7
Result = 2567
Value = 16
Result = 5136
Value = 34
Result = 10786
Value = 55
Result = 16951
  1. C#-এ Array.ConstrainedCopy() মেথড

  2. C#-এ Skip মেথড

  3. C#-এ Array.BinarySearch মেথড

  4. C#-এ Clone() মেথড