class Program
{
static void Main(string[] args)
{
//通过使用$符号初始化一个字符串,可以在字符串中使用占位符来引用变量
int a = 123;
Console.WriteLine($"this value is {a}");
int b = 1;
//其实就是语法糖,编译器还是将它翻译成String.Format 来处理
FormattableString fs = $"a:{a}, b:{b} x+y={a + b}";
Console.WriteLine(fs.Format); //a:{0}, b:{1} x+y={2}
for (int i = 0; i < fs.ArgumentCount; i++)
{
Console.WriteLine($"argument: {i} {fs.GetArgument(i)}");
}
string c = "我爱你";
Console.WriteLine(nameof(c));
//与日期结合的使用,在表达式后面通过冒号连接,设置特定的格式
var s = DateTime.Now;
Console.WriteLine($"{s:D}"); //长日期格式
Console.WriteLine($"{s:d}"); //短日期格式
Console.WriteLine($"{s:yyyy:MM:dd hh:mm:ss}"); //自定义格式
//常用数字
var e = 123;
Console.WriteLine($"{e:x2} {e:C} {e:F} {e:N}");
Console.ReadKey();
}
}