DEV Community

Munisa Kuranbekova
Munisa Kuranbekova

Posted on

C# da input qilish

C# da input qilish C++ da input qilishga o'xshab ketadi. Masalan C++ da int son = 2; string ism = "ilmhub"; char harf ='c'; va shunga o'xshash boshqa o'zgaruvchilarni e'lon qilsak bo'ladi. C# da esa bu ozgina boshqacharoq. C# da o'zgaruvchilar ko'pincha string ko'rinishida qabul qilinadi. Shuning uchun o'zgaruvchilar e'lon qilinayotganda ularni convert qilib , ya'ni bizga kerakli holatga o'tkazib olishimiz zarur. Kod orqali tushuntiradigan bo'lsak:

using Program
{
static void Main()
{

int son= int.Parse(Console.Readline());
char belgi = char.Parse(Console.Readline());
double kasrSon = double.Parse(Console.ReadLine());
bool tekshirish = bool.Parse(Console.Readline());
}

}
Enter fullscreen mode Exit fullscreen mode

shu kodni ishga tushirib har bir o'zgaruvchiga o'zimiz uchun kerakli qiymatlarni kiritishimiz mumkin. String tioida o'zgaruvchi e'lon qilish uchun esa uni Parse qilish shart emas. Uni shundayligicha yozaversak ham bo'ladi:

string ism = Console.ReadLine();

Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →