DEV Community

Alisher Maxamadjonov
Alisher Maxamadjonov

Posted on

1 1 1 1 1

string Interpolation

string Interpolation - q'oshtirnoq ichida o'zgaruvchilardan foydalanish imkonini beradi, yana inject (ukol qilish)

C# da Interpolation ichida, o'zgaruvchidan keyin son yozadigan bo'lsak o'sha son marta bo'sh joy qoldirib beradi.
agar musbat son bersak o'ng tomonga
agar manfiy son bersak chap tomonga

$ belgisi satr literalini interpolyatsiya qilingan qator sifatida belgilaydi. Interpolyatsiya qilingan satr - bu interpolatsiya ifodalarini o'z ichiga olishi mumkin bo'lgan satr harfidir. Interpolyatsiya qilingan satr natija qatoriga echilganda, kompilyator elementlarni interpolyatsiya ifodalari bilan ifoda natijalarining satr tasvirlari bilan almashtiradi.

String interpolyatsiyasi satrlarni formatlash uchun yanada o'qiladigan, qulay sintaksisni ta'minlaydi. String kompozit formatlashdan ko'ra o'qish osonroq.

var name = "Mark";
var date = DateTime.Now;

// Composite formatting:
Console.WriteLine("Hello, {0}! Today is {1}, it's {2:HH:mm} now.", name, date.DayOfWeek, date);
// String interpolation:
Console.WriteLine($"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now.");
// Both calls produce the same output that is similar to:
// Hello, Mark! Today is Wednesday, it's 19:40 now.
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

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

Okay