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

C#-তে int.Parse() এবং Convert.ToInt32-এর মূল পার্থক্য কী?

C#-তে একটি নাম্বারের স্ট্রিং রিপ্রেজেন্টেশনকে ইন্টিজারে কনভার্ট করতে `int.Parse` বা `Convert.ToInt32` মেথড ব্যবহার করা হয়। যদি স্ট্রিংটি কনভার্ট করা না যায়, তবে `int.Parse` বা `Convert.ToInt32` মেথড এক্সসেপশন রিটার্ন করে।

Convert.ToInt32 null ভ্যালু অনুমতি দেয়, এটি কোনো এরর থ্রো করে না। int.Parse null ভ্যালু অনুমতি দেয় না, এবং এটি `ArgumentNullException` এরর থ্রো করে।

int.Parse উদাহরণ

উদাহরণ

class Program
{
    static void Main()
    {
        int res;
        string myStr = "5000";
        res = int.Parse(myStr);
        Console.WriteLine("Converting String is a numeric representation: " + res);
        Console.ReadLine();
    }
}

আউটপুট

Converting String is a numeric representation: 5000

Convert.ToInt32 null এর সাথে উদাহরণ

উদাহরণ

class Program
{
    static void Main()
    {
        int res;
        string myStr = null;
        res = Convert.ToInt32(myStr);
        Console.WriteLine("Converting String is a numeric representation: " + res);
        Console.ReadLine();
    }
}

আউটপুট

Converting String is a numeric representation: 0

int.Parse null এর সাথে উদাহরণ (এক্সসেপশন)

উদাহরণ

class Program
{
    static void Main()
    {
        int res;
        string myStr = null;
        res = int.Parse(myStr);
        Console.WriteLine("Converting String is a numeric representation: " + res);
        Console.ReadLine();
    }
}

আউটপুট

Unhandled exception. System.ArgumentNullException: Value cannot be null.
  1. জাভাস্ক্রিপ্টে '=' এবং '==' অপারেটরের পার্থক্য

  2. MySQL-এ INT এবং INTEGER ডেটা টাইপের পার্থক্য

  3. C++-এ const int*, const int* const, int const* পার্থক্য

  4. পাইথনে স্ট্রিং এবং বাইট স্ট্রিং-এর পার্থক্য