作者perturbed (perturbed seed)
看板C_Sharp
标题Re: [心得] 会员变数与区域变数同名会怎样?!
时间Tue Apr 5 02:11:53 2005
※ 引述《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