【发布时间】:2013-07-23 02:50:21
【问题描述】:
我有这个 foreach 部分,我试图在“result = string.Format”之后添加一行,但我收到以下错误“只能使用赋值、调用、递增、递减、等待和新对象表达式作为一个声明“有人可以告诉我我做错了什么。
foreach (DataRow record in table.Rows)
{
string key = record["Code"] + "_" + record["Description"];
int row = (int)rownum[key];
string date = formatDate(record["ApptDate"].ToString(), "_");
string result = string.Empty;
if (record["Dosage"].ToString() != string.Empty)
result = string.Format("{0}/{1}", test.SharedLib.Application.RemoveTrailingZeroes(record["Dosage"].ToString()),
test.SharedLib.Application.RemoveTrailingZeroes(record["Units"].ToString()));
if (record["Dosage"].ToString() != string.Empty)
result.StartsWith("/") && result.EndsWith("/") ? result.Replace("/", string.Empty) : result;
else if (record["Units"].ToString() != string.Empty)
result = record["Units"].ToString();
dataTable.Rows[row]["ApptDate" + date] = result;
}
【问题讨论】:
-
为什么你的
if块周围没有{}? -
result = result.StartsWith("/") && result.EndsWith("/") ? result.Replace("/", string.Empty) : result;