※ 引述《tomex (tomex_ou)》之銘言:
: public class Test
: {
: protected string LUCK_ID;
: private void TestMethod()
: {
: string LUCK_ID = "重複宣告變數應該要error, 但complie卻成功!";
: }
: }
全域跟區域變數名稱可以相同,但同ㄧ個scope內的變數名稱要惟一。
這樣才會出錯。
1.
public class Test
{
protected string LUCK_ID;
Method1(){}
Method2(){}
Method3(){}...
string LUCK_ID="ReDefined."
}
2.
public class Test
{
protected string LUCK_ID;
private void TestMethod( string LUCK_ID )
{
string LUCK_ID = "ReDefined.";
}
}
--
給小弟賺點p幣...
--
│ˊ
一 今 千口 ──┼ ‧ 一 今 奚佳 ┼ ┤├
心 小壬 工 │ , 心 ┼ ┤├
╰ │ ┤├
╯ ╯╰
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.59.10.250