mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
個人BLOG
it developer
  1. Main page
  2. DotNET
  3. Main content

C# 字符串 前面 美元符号

2018-02-19 136hotness 0likes 0comments

内插字符串以美元符号$开头,后面跟一个""包含的字符串,字符串中大括号包含的内容会由编译器计算成一个字符串,如果是对象的话就会调用对象的ToString方法,然后拼接产生结果。


如果要在内插字符串中包含大括号,就需要连续两个大括号{{ }}这样的。单大括号里的内容不仅仅可以是一个值,表达式也可以

string name = "microsoft";

int age = 23;

Console.WriteLine("{0} is {1} years old.", name, age);

//使用内插字符串

Console.WriteLine($"{name.ToUpper()} is {age * 2} years old.");


Tag: Nothing
Last updated:2018-02-19

mikebai

This person is a lazy dog and has left nothing

Like
< Last article
Next article >

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang