String Interpolation(字串內插)
String Interpolation(字串內插)
Q:What is string interpolation?
A:string interpolation is a way that replaces the value with variable into string. So the string is not always same. the variable can determine it.
Q:What is the form of string interpolation?
A:dollar sign before quotation.
use dollar sign with curly bracket. Compiler will replace it with variable.
syntax:
such as the following code.
//C#
int age=20;
string name="Jay";
//Compiler will replace {name} into variable name as Jay.
Console.WriteLine($"my name is {name}, I am {age} years old.");
/*
output:
my name is Jay, I am 20 years old."
*/
NOTE:
Please pay a lot of attention on the notice.
According to the website $ - 字串內插 - C# 參考 | Microsoft Docs,
version which is under C# 6.0 will NOT support this way.
resources:
more details on
Comments
Post a Comment