C# string interpolation

7 Views
Published
C# string interpolation tutorial example explained

#C# #string #interpolation

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// string interpolation = allows us to insert variables into a string literal
// precede a string literal with $
// {} are placeholders

String firstName = "Bro";
String lastName = "Code";
int age = 21;

Console.WriteLine($"Hello {firstName} {lastName}.");
Console.WriteLine($"You are {age,-10} old.");

Console.ReadKey();
}
}
}
Category
Bro Code
Tags
C#, string interpolation, C# string interpolation
Be the first to comment