Re: [心得] 會員變數與區域變數同名會怎樣?!

看板C_Sharp (C#)作者 (perturbed seed)時間20年前 (2005/04/05 02:06), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #12KO8B4H (C_Sharp)
文章代碼(AID): #12KO8B4H (C_Sharp)