C# string.Format()用法

时间:2022-06-01 21:19:52

C# string.Format()用法例:

sting szNenryoSBTCD="abc";

Datarow[] drs = this.dtNenRyoDat.Select(string.Format("NENRYOU_SBT_CD = ‘{0}‘ ‘", szNenryoSBTCD));

string.Format("NENRYOU_SBT_CD = ‘{0}‘ ‘", szNenryoSBTCD) 就相当于 "NENRYOU_SBT_CD = ‘abc‘ ‘"

使用占位符{0}拼接字符串,多个占位符时将参数依次列在后面,,如

dr = dt.Select(
string.Format("{0} = ‘{1}‘ AND (GYIUSYU_CD = ‘{2}‘ OR GYIUSYU_CD = ‘{3}‘)"
, szSGyomuKBN, this.szEGyoumuKbn, Consts.STR_CONSTANT_GYOUSYU_1, Consts.STR_CONSTANT_GYOUSYU_12)
, "TORIHIKISAKI_CD");