C# input

C# dasturlash tilida uchun Console.ReadLine() buyrug'i orqali foydalanuvchidan ma'lumot qabul qilish mumkin va bu buyruq faqat string tipiga mansub. Agar biz butun, kasr son yoki char qabul qilmoqchi bo'lsak Convert yoki Parse qilishimiz kerak bo'ladi. Masalan: class Program { static void Main(string[] args) { Console.Write("Ismingizni kiriting: "); string name = Console.ReadLine(); Console.WriteLine("Foydalanuvchining ismi " + name); // String dan int ga Convert qilishni birinchi usuli Console.Write("1-sonni kiriting: "); int s1 = Convert.ToInt32(Console.ReadLine()); Console.Write("2-sonni kiriting: "); int s2 = Convert.ToInt32(Console.ReadLine()); int result1 = son1 + son2; Console.WriteLine("Yig'indi: " + result1); // String dan int ga Convert qilishni ikkinchi usul Console.Write("1-sonni kiriting: "); int n1 = int.Parse(Console.ReadLine()); Console.Write("2-sonni kiriting: "); int n2 = int.Parse(Console.ReadLine()); int result2 = n1 + n2; Console.WriteLine("Yig'indi: " + result2); } }

Jan 20, 2025 - 18:02
 0
C# input

C# dasturlash tilida uchun Console.ReadLine() buyrug'i orqali foydalanuvchidan ma'lumot qabul qilish mumkin va bu buyruq faqat string tipiga mansub.

Agar biz butun, kasr son yoki char qabul qilmoqchi bo'lsak Convert yoki Parse qilishimiz kerak bo'ladi.

Masalan:

class Program
{
    static void Main(string[] args)
    {
        Console.Write("Ismingizni kiriting: ");
        string name = Console.ReadLine();
        Console.WriteLine("Foydalanuvchining ismi " + name);

        // String dan int ga Convert qilishni birinchi usuli
        Console.Write("1-sonni kiriting: ");
        int s1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("2-sonni kiriting: ");
        int s2 = Convert.ToInt32(Console.ReadLine());
        int result1 = son1 + son2;
        Console.WriteLine("Yig'indi: " + result1);

        // String dan int ga Convert qilishni ikkinchi usul
        Console.Write("1-sonni kiriting: ");
        int n1 = int.Parse(Console.ReadLine());
        Console.Write("2-sonni kiriting:  ");
        int n2 = int.Parse(Console.ReadLine());
        int result2 = n1 + n2;
        Console.WriteLine("Yig'indi: " + result2);
    }
}

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow