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…


This content originally appeared on DEV Community and was authored by Sanjar Rashidov

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


This content originally appeared on DEV Community and was authored by Sanjar Rashidov


Print Share Comment Cite Upload Translate Updates
APA

Sanjar Rashidov | Sciencx (2025-01-20T16:36:37+00:00) C# input. Retrieved from https://www.scien.cx/2025/01/20/c-input/

MLA
" » C# input." Sanjar Rashidov | Sciencx - Monday January 20, 2025, https://www.scien.cx/2025/01/20/c-input/
HARVARD
Sanjar Rashidov | Sciencx Monday January 20, 2025 » C# input., viewed ,<https://www.scien.cx/2025/01/20/c-input/>
VANCOUVER
Sanjar Rashidov | Sciencx - » C# input. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/20/c-input/
CHICAGO
" » C# input." Sanjar Rashidov | Sciencx - Accessed . https://www.scien.cx/2025/01/20/c-input/
IEEE
" » C# input." Sanjar Rashidov | Sciencx [Online]. Available: https://www.scien.cx/2025/01/20/c-input/. [Accessed: ]
rf:citation
» C# input | Sanjar Rashidov | Sciencx | https://www.scien.cx/2025/01/20/c-input/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.