c# literal string code example

Example 1: c# write variable in string

int age = 22;

Console.WriteLine($"Age: {age}");

Example 2: c# string formatting

name = "Bob";
age = 27;
info = $"Your name is {name} and you are {age} years old";

Example 3: verbatom literal

A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. ... In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence

Example 4: c# string verbatim

//start @ character
string str = @"dont have to escape \ sign, use double "" for single  ";
//dont have to escape \ sign, use double " for single

Tags:

Java Example