Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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# 由于公共属性getter/setter,MVC应用程序中出现服务器错误_C#_.net - Fatal编程技术网

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;
                }
            }
        }

    }