C# “CS1026:) 预期”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10029563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"CS1026: ) expected"
提问by Michael Cole
using (SqlCommand cmd = new SqlCommand("ReportViewTable", cnx)
{ CommandType = CommandType.StoredProcedure })
When I try to open this page in the browser I am getting the
当我尝试在浏览器中打开此页面时,我得到
CS1026: ) expected error
CS1026:) 预期错误
on this line, but I don't see where it's throwing the error. I have read that an ;can cause this issue, but I don't have any of them.
在这一行,但我没有看到它在哪里抛出错误。我已经读过一个;可能会导致这个问题,但我没有任何一个。
I can help with any additional information needed, but I honestly don't know what question I need to ask. I am trying to google some answers on this, but most of them deal with an extra semicolon, which I don't have.
我可以帮助提供所需的任何其他信息,但老实说,我不知道我需要问什么问题。我正在尝试在 google 上搜索一些答案,但其中大多数都处理了一个额外的分号,而我没有。
Any help is appreciated. Thank you.
任何帮助表示赞赏。谢谢你。
采纳答案by FishBasketGordo
If this is .NET 2.0, as your tags suggest, you cannot use the object initializer syntax. That wasn't added to the language until C# 3.0.
如果这是 .NET 2.0,正如您的标签所暗示的那样,您不能使用对象初始值设定项语法。直到 C# 3.0 才将其添加到语言中。
Thus, statements like this:
因此,像这样的语句:
SqlCommand cmd = new SqlCommand("ReportViewTable", cnx)
{
CommandType = CommandType.StoredProcedure
};
Will need to be refactored to this:
将需要重构为:
SqlCommand cmd = new SqlCommand("ReportViewTable", cnx);
cmd.CommandType = CommandType.StoredProcedure;
Your using-statement can be refactored like so:
您的using-statement 可以像这样重构:
using (SqlCommand cmd = new SqlCommand("ReportViewTable", cnx))
{
cmd.CommandType = CommandType.StoredProcedure;
// etc...
}
回答by ionden
You meant this:
你的意思是:
using (SqlCommand cmd = new SqlCommand("ReportViewTable", cnx)) { cmd.CommandType = CommandType.StoredProcedure; }
回答by asdf_enel_hak
Addition to iodenanswers:
补充ioden回答:
Breaking code in multiple lines,
then double click on error message in compile result should redirect to exact location
在多行中破坏代码,
然后双击编译结果中的错误消息应重定向到确切位置
something like:
就像是:



