StackOverflowException on Getter C#

后端 未结 3 1726
旧巷少年郎
旧巷少年郎 2021-01-19 06:41

I am getting a StackOverflowException on the get; of a property in an abstract class.

public abstract class SenseHatSnake
    {

        privat         


        
3条回答
  •  自闭症患者
    2021-01-19 07:37

    This line in SnakeGame causes a recursion

    public readonly Movement Movement = new Movement(SenseHat);
    

    Since Movement is inherited from SnakeGame, its constructor will initialize SnakeGame, calling the line above again to initialize its own Movement field. That results into recursion.

提交回复
热议问题