C#学习教程:设置属性时获取StackOverflowException分享设置属性时获取StackOverflowExceptionpublicListListEmployees(){ListreturnList=newList();varlist=fromuinDB.tabEmployeeselectnew{u.Employeeid,u.Userid,u.Name,u.Lastname,u.Phone1};foreach(vareinlist){Employeeemployee=newEmployee();employee.employeeid=e.employeeid;employee.Userid=e.Userid;employee.name=e.Name;employee.lastnames=e.Lastnames;employee.phone1=e.phone1;returnList.Add(员工);}返回返回列表;这是一个WCF服务,当调用它时,它在类定义StackOverflow中返回一个错误,正好在Employeeid的Set属性中。类定义在这里。[DataContract]publicclassEmpleado{privateint_idEmpleado;[DataMember(IsRequired=false)]publicintidEmpleado{get{return_idEmpleado;}设置{idEmpleado=值;}错误}privateint_idUsuario;[DataMember(IsRequired=false)]publicintidUsuario{get{return_idUsuario;}设置{idUsuario=值;_apellidos;[DataMember(IsRequired=false)]publicstringapellidos{get{return_apellidos;}set{apellidos=value;}}私有字符串_telefono1;[DataMember(IsRequired=false)]publicstringtelefono1{get{return;_telefono1set{telefono1=值;}}}}有谁知道错误在哪里?提前致谢。您通过再次调用属性设置器来设置属性的值,而不是直接设置其支持字段。这会导致无限递归和堆栈溢出。以上就是C#学习教程:设置属性时获取StackOverflowException共享的所有内容。如果对你有用,需要进一步了解C#学习教程,希望大家多多关注——publicintidEmpleado{get{return_idEmpleado;}设置{idEmpleado=值;}//SHOULDBE_idEmpleado=value}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
