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

C#-এ BitConverter.ToInt32() পদ্ধতি


C#-এ BitConverter.ToInt32() পদ্ধতিটি ব্যবহার করা হয় একটি বাইট অ্যারেতে একটি নির্দিষ্ট অবস্থানে চার বাইট থেকে রূপান্তরিত একটি 32-বিট স্বাক্ষরিত পূর্ণসংখ্যা ফেরত দেওয়ার জন্য।

সিনট্যাক্স

সিনট্যাক্স নিম্নরূপ -

public static int ToInt32 (byte[] val, int begnIndex);

উপরে, val হলো বাইট অ্যারে, আর begnIndex হলো val-এ প্রারম্ভিক অবস্থান।

উদাহরণ

এখন একটি উদাহরণ দেখি -

using System; 
public class Demo { 
    public static void Main(){ 
        byte[] arr = { 10, 20, 30, 40, 50}; 
        Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); 
        for (int i = 1; i < arr.Length - 3; i = i + 4) { 
            int res = BitConverter.ToInt32(arr, i); 
            Console.WriteLine("\nValue = "+arr[i]); 
            Console.WriteLine("Result = "+res); 
        } 
    } 
}

আউটপুট

এটি নিম্নলিখিত আউটপুট তৈরি করবে -

Byte Array = 0A-14-1E-28-32
Value = 20
Result = 841489940

উদাহরণ

এখন আরেকটি উদাহরণ দেখি -

using System; 
public class Demo { 
    public static void Main(){ 
        byte[] arr = { 0, 0, 10, 15, 20, 26, 32, 34, 40}; 
        Console.WriteLine("Byte Array = {0} ", BitConverter.ToString(arr)); 
        for (int i = 1; i < arr.Length - 3; i = i + 4) { 
            int res = BitConverter.ToInt32(arr, i); 
            Console.WriteLine("\nValue = "+arr[i]); 
            Console.WriteLine("Result = "+res); 
        } 
    } 
}

আউটপুট

এটি নিম্নলিখিত আউটপুট তৈরি করবে -

Byte Array = 00-00-0A-0F-14-1A-20-22-28
Value = 0
Result = 336529920
Value = 26
Result = 673325082

  1. C# তে ContainsKey() পদ্ধতি

  2. C# Convert.ToInt32 পদ্ধতি

  3. C#-এ Convert.ToInt32 পদ্ধতি

  4. সি শার্পে SequenceEqual মেথড