DEV Community

Shoxjaxon1202
Shoxjaxon1202

Posted on

Input

Input --> Console.ReadLine()
input bu console dan biror malumotni olish. Buning uchun birinchi o'zgaruvchi yaratiladi.

Misol uchun :
string text = Console.ReadLine(); // misol: Ilmhub


~~int num = Console.ReadLine(); ~~ // error

biz int turidagi yani raqam turidagi narsalarni Console dan shunchaki ololmaymiz! Chunki Console.ReadLine() string type da ishlaydi uni raqam ko'rinishida ishlatishimiz uchun biz uni Convert ya'ni string dan int ga o'tkazib olishimiz kerak.

Console.Write("Butun son kiriting: ");
int num = Convert.ToInt32(Console.ReadLine()); // 18
System.Console.WriteLine("Siz kiritgan son bu: " + num);

Yuqorida ko'rsatilganidek Convert.ToInt32 orqali siz uni int ga o'zgartirasiz. ToInt dan keyin 16 , 32 , 64 ham bo'lishi mumkin bu kompyuteringizga bog'liq. 32 deb yozish maslahat beriladi Kompyuter zo'r bo'lsa ham.

Sizlar hozir string va int turida input dan qabul qilishni o'rgangingiz.
Ammo bizda yana boshqa turlar ham bor ular float , char ......

Ularni inputdan qabul qilish uchun biz Parse() methodidan foydalanamiz bu qanday ishlaydi :

                                    Float
Enter fullscreen mode Exit fullscreen mode

float kasrSon = float.Parse(Console.ReadLine());// misol: 4.5

                                    Char
Enter fullscreen mode Exit fullscreen mode

char belgi = char.Parse(Console.ReadLine()); // faqat bitta qabul qiladi misol: $

Yana bir narsa biz Int ni ham Parse qilishimiz mumkin.

                                    Int
Enter fullscreen mode Exit fullscreen mode

int ParsedNum = int.Parse(Console.ReadLine()); // 4

Xuddi shu kabi boshqa turdagi malumotlar ham Parse() orqali input qilinadi. Unutmang string uchun Parse yoki Convert qilish kerak emas.
Yuqorida aytganimdek Console.ReadLine() shundoq ham string da ishlaydi.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay