이전게시판/C#

프로퍼티 스택오버플로우..

ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ 2018. 8. 10. 21:15

    public uint dwIndex

    {

        get

        {

            // 나중에 데이터 변환해야함..

            return dwIndex;

        }


        set

        {

            dwIndex = value;

        }

    }


dwIndex라는 필드에 값을 넣으니 스택오버플로우 에러가 났다.


StackOverflowException: The requested operation caused a stack overflow.

MsgText.set_dwIndex (UInt32 value) (at Assets/1_Scripte/Data/MsgText.cs:17)

MsgText.set_dwIndex (UInt32 value) (at Assets/1_Scripte/Data/MsgText.cs:17)

MsgText.set_dwIndex (UInt32 value) (at Assets/1_Scripte/Data/MsgText.cs:17)

MsgText.set_dwIndex (UInt32 value) (at Assets/1_Scripte/Data/MsgText.cs:17)

...


확인해보니 dwIndex는 선언된 변수가 아니라 자기가 가지고 있는 속성? 이고

그 속성에 값을 넣어주므로 계속 set이 호출된다는 것이다.

dwIndex = value;

=> 어? dwIndex 속성에 값을 넣어주네? set 프로퍼티 호출!

dwIndex = value;

=> 어? dwIndex 속성에 값을 넣어주네? set 프로퍼티 호출!

무한반복..

그래서 아래와 같이
필드를 선언하고, 그에 따른 프로퍼티 속성을 선언했다.
그리고 값을 넣어줄 때 속성을 넣어주니 더이상 스택 오버 플로우가 일어나지 않았다!

private uint dwIndex

public uint INDEX

{

get

      {

          // 나중에 데이터 변환해야함..

          return dwIndex;

      }


      set

      {

          dwIndex = value;

      }

}