Format value in string interpolation - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Format value in string interpolation

Demo Code

using System;//from ww w  .j  a v a 2 s. c o  m
class Program
{
   static void Main(string[] args)
   {
      var weight = 1.88; // in kilograms
      var price = 4.99M; // in pounds sterling
      var fruit = "Abc"; // strings use double-quotes
      int population = 12341;
      Console.WriteLine($"The UK population is {population}.");
      Console.Write($"The UK population is {population:N0}. ");
      Console.WriteLine($"{weight}kg of {fruit} costs {price:C}.");
   }
}

Result


Related Tutorials