代码之家  ›  专栏  ›  技术社区  ›  sree aneev

UserControl文本框获取设置属性

  •  0
  • sree aneev  · 技术社区  · 12 年前

    我收到以下错误:

     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;
        }
    }
    
    3 回复  |  直到 12 年前
        1
  •  2
  •   Prateek Singh    12 年前

    在代码中查看我的评论-

    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;
            }
        }
    
        2
  •  1
  •   Akshay Joy    12 年前

    您正在调用Set属性Inifinite Manner

      DecPlaces = value;
    

    使用一些lcoal变量来完成此操作。

    int m= value;
    
        3
  •  0
  •   Sameer Singh    12 年前

    这是你的问题:

    DecPlaces = value;
    

    你在自我参照。你一直在给你的二传手打电话。只要去掉那条线,你就应该表现得很好。