Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么我会有例外;System.StackOverflowException“;?_C#_Asp.net - Fatal编程技术网

C# 为什么我会有例外;System.StackOverflowException“;?

C# 为什么我会有例外;System.StackOverflowException“;?,c#,asp.net,C#,Asp.net,我有这个密码。代码从表、表内容、一些文本框和其他内容中获取一些值。当我点击submit按钮时,我会得到一个值并输入“st”(type class student)并输入数据库。但是它在列表属性“get{….}”中显示了一个异常“System.StackOverflowException” public StudentManager() :base(ConfigurationManager.ConnectionString[“con”].ConnectionString) { } 公共覆盖无效添加

我有这个密码。代码从表、表内容、一些文本框和其他内容中获取一些值。当我点击submit按钮时,我会得到一个值并输入“st”(type class student)并输入数据库。但是它在列表属性“get{….}”中显示了一个异常“System.StackOverflowException”

public StudentManager()
:base(ConfigurationManager.ConnectionString[“con”].ConnectionString)
{
}
公共覆盖无效添加(学生实体)
{
//添加到数据库
}
受保护的无效提交按钮单击(对象发送者,事件参数e)
{
学生st=新学生();
st.id=Convert.ToInt32(IdTextBox.Text);
st.AVG=Convert.ToDouble(AVGTextBox.Text);
st.date=dateCalendar.TodaysDate;
st.educationInfo=educationInfo文本框.Text;
fa系=新系();
fa.id=Convert.ToInt32(faculthydropdownlist.SelectedValue);
st.faculty=fa;
st.fatherName=fatherNameTextBox.Text;
st.fName=fNameTextBox.Text;
st.lName=lNameTextBox.Text;
st.motherName=motherNameTextBox.Text;
st.password=passwordTextBox.Text;
st.personalInfo=personalinfortbox.Text;
StudentManager sm=新的StudentManager();
sm.Add(st);
}
公立班学生
{
公共int id{get;set;}
公共学院{get;set;}
公共双平均值{get;set;}
公共日期时间日期{get;set;}
公共字符串教育信息{get;set;}
公共字符串父名称{get;set;}
公共字符串fName{get;set;}
公共字符串lName{get;set;}
公共字符串名称{get;set;}
公共字符串密码{get;set;}
公共字符串personalInfo{get;set;}
私有列表属性;
公共列表属性
{
得到
{
属性=新列表();
SqlParameter sp=新的SqlParameter();
Add(新的SqlParameter(“id”,this.id));
Add(新的SqlParameter(“faculty”,this.faculty));
Add(新的SqlParameter(“AVG”,this.AVG));
Add(新的SqlParameter(“date”,date));
Add(新的SqlParameter(“educationInfo”,educationInfo));
Add(新的SqlParameter(“父名”,父名));
Add(新的SqlParameter(“lName”,lName));
Add(新的SqlParameter(“motherName”,motherName));
添加(新的SqlParameter(“密码”,password));
添加(新的SqlParameter(“personalInfo”,personalInfo));
返回属性;
}
}
}

这是因为类中的属性进行递归调用

public List<SqlParameter> attributes
        {
            get
            {
                Attributes = new List<SqlParameter>();
                SqlParameter sp = new SqlParameter();
                attributes.Add(new SqlParameter("id",this.id));
                attributes.Add(new SqlParameter("faculty", this.faculty));
                attributes.Add(new SqlParameter("AVG", this.AVG));
                attributes.Add(new SqlParameter("date", date));
                attributes.Add(new SqlParameter("educationInfo",educationInfo));
                attributes.Add(new SqlParameter("fatherName", fatherName));
                attributes.Add(new SqlParameter("lName", lName));
                attributes.Add(new SqlParameter("motherName", motherName));
                attributes.Add(new SqlParameter("password", password));
                attributes.Add(new SqlParameter("personalInfo", personalInfo));
                return Attributes;
            }
公共列表属性
{
得到
{
属性=新列表();
SqlParameter sp=新的SqlParameter();
Add(新的SqlParameter(“id”,this.id));
Add(新的SqlParameter(“faculty”,this.faculty));
Add(新的SqlParameter(“AVG”,this.AVG));
Add(新的SqlParameter(“date”,date));
Add(新的SqlParameter(“educationInfo”,educationInfo));
Add(新的SqlParameter(“父名”,父名));
Add(新的SqlParameter(“lName”,lName));
Add(新的SqlParameter(“motherName”,motherName));
添加(新的SqlParameter(“密码”,password));
添加(新的SqlParameter(“personalInfo”,personalInfo));
返回属性;
}
要解决这个问题,我觉得最好将其转换为方法,而不是使用属性。可以这样做:

public List<SqlParameter> GetAttributes()
{
    //replace your code here to get attributes
    List<SqlParameter> attributes = new List<SqlParameter>();
    SqlParameter sp = new SqlParameter();
    attributes.Add(new SqlParameter("id", this.id));
    attributes.Add(new SqlParameter("faculty", this.faculty));
    attributes.Add(new SqlParameter("AVG", this.AVG));
    attributes.Add(new SqlParameter("date", date));
    attributes.Add(new SqlParameter("educationInfo", educationInfo));
    attributes.Add(new SqlParameter("fatherName", fatherName));
    attributes.Add(new SqlParameter("lName", lName));
    attributes.Add(new SqlParameter("motherName", motherName));
    attributes.Add(new SqlParameter("password", password));
    attributes.Add(new SqlParameter("personalInfo", personalInfo));
    return attributes;
} 
public List GetAttributes()
{
//在此处替换代码以获取属性
列表属性=新列表();
SqlParameter sp=新的SqlParameter();
Add(新的SqlParameter(“id”,this.id));
Add(新的SqlParameter(“faculty”,this.faculty));
Add(新的SqlParameter(“AVG”,this.AVG));
Add(新的SqlParameter(“date”,date));
Add(新的SqlParameter(“educationInfo”,educationInfo));
Add(新的SqlParameter(“父名”,父名));
Add(新的SqlParameter(“lName”,lName));
Add(新的SqlParameter(“motherName”,motherName));
添加(新的SqlParameter(“密码”,password));
添加(新的SqlParameter(“personalInfo”,personalInfo));
返回属性;
} 

从代码中删除
私有列表属性;
这是因为类中的属性进行递归调用

public List<SqlParameter> attributes
        {
            get
            {
                Attributes = new List<SqlParameter>();
                SqlParameter sp = new SqlParameter();
                attributes.Add(new SqlParameter("id",this.id));
                attributes.Add(new SqlParameter("faculty", this.faculty));
                attributes.Add(new SqlParameter("AVG", this.AVG));
                attributes.Add(new SqlParameter("date", date));
                attributes.Add(new SqlParameter("educationInfo",educationInfo));
                attributes.Add(new SqlParameter("fatherName", fatherName));
                attributes.Add(new SqlParameter("lName", lName));
                attributes.Add(new SqlParameter("motherName", motherName));
                attributes.Add(new SqlParameter("password", password));
                attributes.Add(new SqlParameter("personalInfo", personalInfo));
                return Attributes;
            }
公共列表属性
{
得到
{
属性=新列表();
SqlParameter sp=新的SqlParameter();
Add(新的SqlParameter(“id”,this.id));
Add(新的SqlParameter(“faculty”,this.faculty));
Add(新的SqlParameter(“AVG”,this.AVG));
Add(新的SqlParameter(“date”,date));
Add(新的SqlParameter(“educationInfo”,educationInfo));
Add(新的SqlParameter(“父名”,父名));
Add(新的SqlParameter(“lName”,lName));
Add(新的SqlParameter(“motherName”,motherName));
添加(新的SqlParameter(“密码”,password));
添加(新的SqlParameter(“personalInfo”,personalInfo));
    // this should be a Get() method, not a property.
    public List<SqlParameter> GetAttributes()
    {
        attributes = new List<SqlParameter>();
        SqlParameter sp = new SqlParameter();
        attributes.Add(new SqlParameter("id",this.id));
        attributes.Add(new SqlParameter("faculty", this.faculty));
        attributes.Add(new SqlParameter("AVG", this.AVG));
        attributes.Add(new SqlParameter("date", date));
        attributes.Add(new SqlParameter("educationInfo",educationInfo));
        attributes.Add(new SqlParameter("fatherName", fatherName));
        attributes.Add(new SqlParameter("lName", lName));
        attributes.Add(new SqlParameter("motherName", motherName));
        attributes.Add(new SqlParameter("password", password));
        attributes.Add(new SqlParameter("personalInfo", personalInfo));
        return attributes;
    }
    public List<SqlParameter> attributes
    {
        get
        {
            Attributes = new List<SqlParameter>();
            SqlParameter sp = new SqlParameter();
            attributes.Add(new SqlParameter("id",this.id));
            attributes.Add(new SqlParameter("faculty", this.faculty));
            attributes.Add(new SqlParameter("AVG", this.AVG));
            attributes.Add(new SqlParameter("date", date));
            attributes.Add(new SqlParameter("educationInfo",educationInfo));
            attributes.Add(new SqlParameter("fatherName", fatherName));
            attributes.Add(new SqlParameter("lName", lName));
            attributes.Add(new SqlParameter("motherName", motherName));
            attributes.Add(new SqlParameter("password", password));
            attributes.Add(new SqlParameter("personalInfo", personalInfo));
            return Attributes;
        }

    }
    public List<SqlParameter> attributes
    {
        get
        {
            var myAttributes= new List<SqlParameter>();
            SqlParameter sp = new SqlParameter();
            myAttributes.Add(new SqlParameter("id",this.id));
            myAttributes.Add(new SqlParameter("faculty", this.faculty));
            myAttributes.Add(new SqlParameter("AVG", this.AVG));
            myAttributes.Add(new SqlParameter("date", date));
            myAttributes.Add(new SqlParameter("educationInfo",educationInfo));
            myAttributes.Add(new SqlParameter("fatherName", fatherName));
            myAttributes.Add(new SqlParameter("lName", lName));
            myAttributes.Add(new SqlParameter("motherName", motherName));
            myAttributes.Add(new SqlParameter("password", password));
            myAttributes.Add(new SqlParameter("personalInfo", personalInfo));
            return myAttributes;
        }

    }