C# 错误消息:类型或命名空间定义,或预期的文件结尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10976243/
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
Error Message: Type or namespace definition, or end-of-file expected
提问by TechGuy
I've searched the internet, all previous answers said that a semicolon is missing. That's not the problem. What else can cause this error? In the third site, several people asked this question but this scenario is different.
我在互联网上搜索过,之前所有的答案都说缺少分号。那不是问题。还有什么可能导致此错误?在第三个站点中,有几个人问了这个问题,但这种情况不同。
Error is > Type or namespace definition, or end-of-file expected
误差>类型或命名空间定义,或结束文件人口会d
public partial class SeenSMS : System.Web.UI.UserControl
{
//temp sql connection
//public SqlConnection mycon;
SqlConnection mycon = new SqlConnection(@"Data Source=ASOFT20\MAMUT;Initial Catalog=ViltraNew;UserID=sa;Password=sa123");
protected void Page_Load(object sender, EventArgs e)
{
string[] msg_arr = Request.QueryString["arr"].Split('|');
if (!IsPostBack)
{
string Moose = Request.QueryString[1];
}
if (msg_arr != null)
{
if ((msg_arr.Length == 3) && (msg_arr[1].ToLower() == "slett"))
{
int Hours = Convert.ToInt32(msg_arr[2]);
if (Hours > 0)
{
string username = msg_arr[0];
SqlCommand com = new SqlCommand("SELECT count(*) as count FROM Animal Where Hours=@Hours", mycon);
com.Parameters.AddWithValue("@Hours",Hours);
using (SqlDataReader reader = com.ExecuteReader())
{
if(reader.HasRows)
{
while (reader.Read())
{
// int number = Convert.ToInt32(con.ExecuteReader());
int number = Convert.ToInt32(reader["count"]);
}
}
else{
}
}
}
// if( number == 0)
// {
// Response.Write("Improper Plain Summaries.");
// }
// else
{
}
}
}
}
public bool number { get; set; }
public object Hours { get; set; }}
// public System.Collections.Specialized.NameValueCollection Moose { get; set; }
// public string Value { get; set; }
// public object msg_arr { get; set; }
}
}
采纳答案by Jürgen Steinblock
This line:
这一行:
public object Hours { get; set; }}
Your have a redundand }at the end
你拥有了一个redundand}末
回答by Po-ta-toe
- Make sure you have System.Web referenced
- Get rid of the two } at the end.
- 确保你有 System.Web 引用
- 最后去掉两个 } 。
回答by stay_hungry
You have extra brackets in Hours property;
你在 Hours 属性中有额外的括号;
public object Hours { get; set; }}

