C# 由于公共属性getter/setter,MVC应用程序中出现服务器错误
当我这样做的时候,它就起作用了C# 由于公共属性getter/setter,MVC应用程序中出现服务器错误,c#,.net,C#,.net,当我这样做的时候,它就起作用了 public int IndicationCalculatorGroupId { get; set; } 然而,这似乎不起作用。基本上,我希望自定义setter,以便在设置它时,它将使用该值进行设置,同时在SelectList中搜索该值以使用另一个值设置另一个属性 我这样做对吗?如果您想要自定义getter/setter,您必须创建底层字段。否则,在getter内部调用IndicationCalculatorGroupId将产生堆栈溢出。@slandau:Yes
public int IndicationCalculatorGroupId { get; set; }
然而,这似乎不起作用。基本上,我希望自定义setter,以便在设置它时,它将使用该值进行设置,同时在SelectList中搜索该值以使用另一个值设置另一个属性
我这样做对吗?如果您想要自定义getter/setter,您必须创建底层字段。否则,在getter内部调用
IndicationCalculatorGroupId
将产生堆栈溢出。@slandau:Yes。此代码将导致堆栈溢出异常
:)警告-具有副作用的属性设置器通常不是一个好主意。确保此行为有良好的文档记录!
public int IndicationCalculatorGroupId
{
get
{
return IndicationCalculatorGroupId;
}
set
{
IndicationCalculatorGroupId = value;
SelectList tempList = Chatham.Web.Models.Shared.DropDownData.IndicationsGroup(SessionManager.Company.EntityID, ICConstants.IndicationsCalculatorGroupType);
foreach (SelectListItem item in tempList)
{
if (value.ToString() == item.Value)
{
GroupDisplayName = item.Text;
break;
}
}
}
}