Variable Interpolation in C#

Now we are going to learn about the variable interpolation C#.
  • 8206

Introduction

Changing the place of variables is called the Variable interpolation with there values inside string literals. String is the immovable in C# programming language but modification of the string is possible by the Variable interpolation. We have use {0} {1} {2} in our program, this represents the position of the variables.

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

 namespace ConsoleApplication6
{
    class Program
    {
        static void Main()
        {
            int age = 34;
            string name = "Rajan singh";
            string designation = " admin";
            string output;
            output = string.Format("{0} is {1} years old, and he is {2} in NPT company.",
                name, age,designation);
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }
}

Output

variable8.jpg

© 2020 DotNetHeaven. All rights reserved.