[英]why am I getting this syntax error
if(gasType.Items.Add("3.19") == checked)
{
}
I keep getting a Syntax error stating that I am missing ( anything I am doing wrong? 我一直收到一个语法错误,说明我错过了(我做错了什么?
checked
is a keyword - you can't declare an identifier called that. checked
是一个关键字 - 您不能声明一个名为的标识符。 You should have an error at the point of its declaration, too. 你的声明也应该有一个错误。
The reason you're getting that particular error is that it's expecting a checked expression, eg 你得到那个特定错误的原因是它期望一个检查表达式,例如
if (gasType.Items.Add("3.19") == checked(y + 1 == 20))
If you really want to use the name checked
, you could prefix it with @
like this: 如果你真的想使用
checked
的名字,你可以在它前面添加@
如下所示:
bool @checked = true;
if (gasType.Items.Add("3.19") == @checked)
I wouldn't recommend it though. 我不会推荐它。
我不确定你在这里尝试做什么,但是在C#中检查是一个关键字
Add()方法不返回值,您尝试比较它。
If the item is a list of any sort, the Add() method doesn't return the object added. 如果该项是任何排序的列表,则Add()方法不会返回添加的对象。 So, what you're really saying is if( == checked).
所以,你真正说的是if(== checked)。
I'm not entirely sure what you're looking to do with this, but definitely rethink your approach. 我不完全确定你想要做什么,但绝对重新考虑你的方法。
真正的问题很可能是,如果你的Items.Add()
方法是一个股票CLR集合(似乎很可能),就像SCG.List<T>
一个实例, Add()
方法几乎肯定会返回void
:没有什么可以相比。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.