DEV Community

asilbek ibragimov
asilbek ibragimov

Posted on

Formatlash

C# dasturlash tilida formatish turli usullarda amalga 
oshiriladi, Eng kop ishlatiladigan usullardan biri String 
Format va Interpolation ($ belgisi yor ishlatiladi.
Enter fullscreen mode Exit fullscreen mode

String-Format ga misol:

int yosh = 24;
double kasSon = 12.2;
string ism = "ilmhub";
string natija = String-Format ("Mening yoshim {0}, \nMen
kiritgan kasrSon: {1),\nMening ismim (2}", yosh, kasrSon, ism);

Console. WriteLine(natija);

Bu yerda {0) va (1) o'rin bosuchi (placehold) sifatida ishlatiladi, ularni is va yosh o'zgaruvchilari qiy,ati bilan to' ldiradi.

 Interpolation - $ belgisi yordamida formatlab chop etish, 
 qo'shtirnoq ichida inject(ukol) qilish, o' zgaruvchilardan 
 foydalanish.
Enter fullscreen mode Exit fullscreen mode

Console.Write("Enter the number: ");
var number = Convert. ToInt32 (Console.ReadLine());
Console.Write("Enter your name: ");
string? ism = Console.ReadLine();
Console.WriteLine($"Mening ismim: (ism). \nMen kiritgan ragam: (number}");

Top comments (0)