只有转让,电话,递增,递减,在等待着,新的对象表达式可以用作声明 [英] Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

查看:199
本文介绍了只有转让,电话,递增,递减,在等待着,新的对象表达式可以用作声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的foreach部分,我想我的结果=的String.format后添加行,但我得到以下错误只有分配,调用,递增,递减,在等待着,可用于新的对象表达式作为一个声明谁能告诉我什么我做错了。

 的foreach(在table.Rows DataRow的记录)
{
串键=记录[编号] +_+纪录[说明];
INT行=(int)的ROWNUM [关键]

字符串日期= formatDate(记录[ApptDate]的ToString(),_);

字符串结果=的String.Empty;
如果(记录[用法用量]。的ToString()!=的String.Empty)
结果=的String.Format({0} / {1},test.SharedLib.Application.RemoveTrailingZeroes( 。纪录[用法用量]的ToString()),
test.SharedLib.Application.RemoveTrailingZeroes(记录[单位]的ToString()));
如果(记录[用法用量]的ToString()=的String.Empty。!)
result.StartsWith(/)及和放大器; result.EndsWith(/)? result.Replace(/,的String.Empty):结果;
,否则如果(记录[单位]的ToString()=的String.Empty。!)
结果=记录[单位]的ToString()。

dataTable.Rows [行] [ApptDate+日期] =结果;
}


解决方案

 <$ C (!纪录[用法用量]的ToString()=的String.Empty)$ C>如果
result.StartsWith(/)及和放大器; result.EndsWith(/)? result.Replace(/,的String.Empty):结果;



第二行还没有一个说法,它是一个表达式。并不是所有的表达式可以在C#中的语句,所以这是一个语法错误。



想必你的意思是这样的结果分配给结果

 如果(!纪录[用法用量]的ToString()=的String.Empty)
结果=(result.StartsWith(/)及与放大器; result.EndsWith(/))? result.Replace(/,的String.Empty):结果;



此外,你应该考虑是否的尸体C> / 其他用大括号块( {} )。如果没有括号,以何种方式这些块窝不直观,而且会妨碍日后的维护。 (例如,你能分辨出哪如果阻止如果块将属于哪一种?请问旁边的人谁继承其他这个项目将不仅能分辨出来,但明白筑巢是什么的的?让它明确的!)


I have this foreach section and i am trying to add a line after my "result = string.Format" but i get the following error "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement" can someone tell me what i am doing wrong.

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 (record["Dosage"].ToString() != string.Empty)
    result.StartsWith("/") && result.EndsWith("/") ? result.Replace("/", string.Empty) : result;

The second line there is not a statement, it is an expression. Not all expressions can be statements in C#, so this is a syntax error.

Presumably you meant to assign the result of this to result:

if (record["Dosage"].ToString() != string.Empty)
    result = (result.StartsWith("/") && result.EndsWith("/")) ? result.Replace("/", string.Empty) : result;

Further, you should consider enclosing the bodies of if / else blocks with braces ({}). Without braces, the way in which these blocks nest is not intuitive, and it will hamper future maintenance. (For example, can you tell which if block the else if block will belong to? Will the next person who inherits this project be able to not only tell the difference, but understand what nesting was intended? Make it explicit!)

这篇关于只有转让,电话,递增,递减,在等待着,新的对象表达式可以用作声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆