Stack overflow exception in C# setter

前端 未结 4 1207
星月不相逢
星月不相逢 2020-11-28 15:12

This works:

using System;
using ConstraintSet = System.Collections.Generic.Dictionary;

namespace ConsoleApplication2
{
    class         


        
4条回答
  •  温柔的废话
    2020-11-28 15:23

    You cannot use the same variable name inside the getter and setter. This will cause it to call itself and will eventually lead to a stack overflow. Too much recursion.

    You'll need a backing variable:

    private ConstraintSet _a;
    public ConstraintSet a { get { return _a; } set { _a = value; } }
    

提交回复
热议问题