0

我收到以下错误:

 An unhandled exception of type 'System.StackOverflowException'
 occurred in ciscontrols.dll

以下是相关代码:

private int Dval;
public int DecPlaces
{
    get { return Dval; }
    set
    {
        DecPlaces = value;
        if (value < 2)
        {
            throw new ArgumentOutOfRangeException("decplaces", "decimal places minimum value should be 2.");
        }
        else this.Dval = value;
    }
}
4

3 回答 3

2

请参阅我在代码中的评论 -

private int Dval;
    public int DecPlaces
    {
        get { return Dval; }
        set
        {
            //DecPlaces = value;  **** This is calling set method again, hence the exception. Just comment this line

            if (value < 2)
            {
                throw new ArgumentOutOfRangeException("decplaces", "decimal places minimum value should be 2.");
            }
            else this.Dval = value;
        }
    }
于 2013-03-08T07:25:57.037 回答
1

您正在调用 Set Property Infinite Manner

  DecPlaces = value;

使用一些 lcoal 变量来做到这一点。

int m= value;
于 2013-03-08T07:24:04.090 回答
0

这是你的问题:

DecPlaces = value;

你是自引用的。你一直打电话给你的二传手。只需删除那条线,你应该会很好。

于 2013-03-08T07:26:07.147 回答