DEV Community

Mushtariy
Mushtariy

Posted on

4 4 5 5 5

Formatlash

C# dasturlash tilidaformatlash turli usullarda oshiriladi, eng ko'p ishlatiladigan usullardan biri String.Format va interpolation($ belgisi yordamida) ishlatiladi.

String.Format ga misol;

int yosh = 14;
double kasrSon = 12.2;
string ism = "Mushtariy";
string natija = String.Format{"Mening yoshim {0},/nMen kiritgan kasr {1},/nMening ismim {2}", yosh, kasrSon, ism};
Console.WriteLine(natija);

Enter fullscreen mode Exit fullscreen mode

Formatlash yordamida sonlarni ko'rinishini o'zgartirish mumkin.

Bu misolda {0:C} format kodi 'C' {Currency} yordam beradi;

double narx = 1234.56;
string nar = String.Format("Narx: {0:C}", narx);
Console.WriteLine(nar);
Enter fullscreen mode Exit fullscreen mode

sonlarni xona bo'yicha formatlash

int son = 42;
string ff = String.Format("Son: {0:D5}", son);
Console.WriteLine(ff);
Enter fullscreen mode Exit fullscreen mode

Foiz formatlash
{0:P}formatda yoziladi

double foiz = 0.875;
string son = String.Format("Foiz: {0:P2}", foiz);
Console.WriteLine(son);

Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (1)

Collapse
 
sabrina_abcdna123 profile image
Sabrina

shik shak shok

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay