C# input

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);
    }
}



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.