DEV Community

Mushtariy
Mushtariy

Posted on

Input

"Console.ReadLine()" - input qilish uchun kerak.

"Console.ReadLine()" - faqat stringga ishlaydi.

int, double, float, char lar bilan input ishlatish uchun.int a = Convert.ToInt32(Console.ReadLine());

Convert.To.va data type yoziladi.

Interpolation - bu qo'shtirnoq ichida o'zgaruvchilardan foydalanish imkoniyatini beradi.

$" " - oldindan bu belgini foydalanish kerak

Double ga misol:

Console.Write("Biror bir xaqiqiy son kiirting: ");
double kasrSon = Convert.ToDouble(Console.ReadLine());
Console.WriteLine($"Kiritilgan kasrSon: {kasrSon}");
Enter fullscreen mode Exit fullscreen mode

Char ga misol:

Console.Write("Biror bir belgi kiirting: ");
char belgi = Convert.ToChar(Console.ReadLine());
Console.WriteLine($"Kiritilgan belgi: {belgi}");
Enter fullscreen mode Exit fullscreen mode

Misol:

class Program
{
    static void Main()
    {
        Console.Write("Mashinangiz bormi? (ha/yo'q): ");
        string javob = Console.ReadLine().ToLower();
        bool mashinaBor = javob == "ha";

        if (mashinaBor)
        {
            Console.WriteLine("Sizning mashinangiz bor.");
        }
        else
        {
            Console.WriteLine("Sizning mashinangiz yo'q.");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
sabrina_abcdna123 profile image
Sabrina

YORVORATION