作者Dacool (大褲)
看板C_Sharp
標題[問題] 使用properties跑出無窮迴圈或無窮遞迴的警告
時間Sun Dec 7 00:28:12 2008
在一開始未把相關變數改成properties使用時,只是單純的用get跟set的function
改成properties後,每次run程式時,正當我有call到properties裡的get
那就會在get的return x那邊,跳出查看是否有無窮迴圈的這警告
call set時,就是 X = value那邊
我properties是寫在base class裡,想請問一下到底怎麼了。
public int X
{
get
{ -----------
|return X;| ------StackOverflowExceptio 未處理
----------- 請確定沒有無限迴圈,或無限遞迴的情況。
}
set
{
X = value;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.115.145.24
1F:推 toki:你的 proterty Get X 又 return X,根本就雞生蛋蛋生雞啊 12/07 00:44
2F:→ Dacool:哈...蠢斃了...感謝 12/07 00:51