iT邦幫忙

1

c# string 前面一個 $ 是什麼

c#
  • 分享至 

  • xImage

string aaa="apple";
string bbb="ball";

string str = $"a={aaa}&b={bbb}";

這個是甚麼用法
查關鍵字 : $ in front of string c# 沒結果
c# string 前面一個 $ 沒結果

powerc iT邦新手 1 級 ‧ 2022-08-12 16:21:07 檢舉
我用 $ in front of string c# 就找到了
https://stackoverflow.com/questions/31014869/what-does-mean-before-a-string
搜尋 字串插補
感謝兩位!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
科科
iT邦研究生 1 級 ‧ 2022-08-12 15:35:12
最佳解答

C# 功能 : 字串插補

這很常見喔,google的關鍵字多換幾個其實就找的到了

好的謝謝~~

0
mantissa23bit
iT邦新手 4 級 ‧ 2022-08-12 15:28:13

那是正規表示式的字元
C#正規表示式

感謝~~~~~!!

5
緯大啊緯大人
iT邦研究生 1 級 ‧ 2022-08-12 16:38:45

跟string.Format差不多功用

串字串又有一堆參數時,就不用+來+去這麼醜陋了

用法大概像這樣

string product = "書";
int price = 580;

//商品:書,價格580元

//$用法
string summary = $"商品:{product},價格:{price.tostring()}元";

//string.Format用法
string summary2 = string.Format("商品:{0},價格:{1}元",product,price.tostring());

//比較難看的用法
string summary3 = "商品:" + product + ",價格:" + price.tostring() + "元";

感謝補充 之前都是寫其他兩種方式

我要發表回答

立即登入回答