码迷,mamicode.com
首页 > Windows程序 > 详细

C# $插值符号

时间:2019-11-22 15:22:55      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:就是   语法   code   出现   字符   class   概述   作用   result   

概述

  • $ 符是在C#6.0出现的一个新特性,本质就是C#的一个语法糖,作用在于替代当前的String.format(),简化其过程。他们的作用都在于为字符串提供占位符,并为字符串传入变量。

用法

  • 关于string.Format()用法:
string strA = "A";
string strB = "b";
string result = string.Format("A:{0}, B:{1}", strA, strB);
  • 关于$符用法:
string strA = "A";
string strB = "b";
string result = $"A:{strA}, B:{strB}";

C# $插值符号

标签:就是   语法   code   出现   字符   class   概述   作用   result   

原文地址:https://www.cnblogs.com/LuckyZLi/p/11911617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!