C_Sharp 板


LINE

結論: 在 C# 6.0 裡,這條規則應會被移除 ※ 引述《mingpepe ()》之銘言: : 編譯錯誤訊息:無法在此範圍宣告名為 'i'的變數,因為其可能賦予 'i'不同的意義 : 為什麼呢? 用 ildasm 去看編出來的 CIL, 我覺得這限制單純來自 C# compiler; 而非 CLR : → mingpepe: 是的 我當然了解這是C#不是C++ 我好奇的是理由 05/17 23:42 : → mingpepe: 不同的語言有不同的語法 也會帶來不同的好處與壞處 05/17 23:42 http://blogs.msdn.com/b/ericlippert/archive/2009/06/22/why-doesn-t-c-implement-top-level-methods.aspx "I am asked "why doesn't C# implement feature X?" all the time. The answer is always the same: because no one ever designed, specified, implemented, tested, documented and shipped that feature. All six of those things are necessary to make a feature happen. All of them cost huge amounts of time, effort and money. Features are not cheap, and we try very hard to make sure that we are only shipping those features which give the best possible benefits to our users given our constrained time, effort and money budgets." 有的時候,所謂「好處、壞處」不只是語言本身,還得考量額外的因 素,例如,設計、實作、測試、維護 compiler 的成本 可說是 software business (業界) vs. software engineering (學界) 的微妙差異 :D : → mingpepe: 既然在for迴圈外無法存取變數i 有什麼樣的理由會限制 05/17 23:43 : → mingpepe: 不能再次宣告同名的變數 05/17 23:44 : C#5.0 Spec 7.6.2.1 有提到 http://stackoverflow.com/questions/29750618/lambda-parameter-conflicting-with-class-field-on-accessing-field-in-later-scope "The rule is gone for good; see Jon's answer for details." https://github.com/dotnet/roslyn/issues/2110 "It is a deliberate change. Not quite up there to advertise as a feature, we have nevertheless gotten rid of the "invariant meaning" rule that used to cause your example to error. The rule was well intended, in that it was supposed to minimize the risk of "moving code around" in a way that would silently change its meaning. However, everyone we talked to only seemed to know about the rule from when it was causing them unnecessary grief - no-one had ever been saved by its prohibitions. Furthermore, the extra tracking necessary in the compiler to enforce the rule interactively was causing significant complications to the code, as well as non-trivial performance overhead. Now, if it were a good rule we would have kept it anyway, but it isn't! So it's gone." 如開頭結論所述,這條規則會在 C# 6.0 被移除 --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 68.4.115.53
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_Sharp/M.1431881354.A.7F8.html ※ 編輯: AmosYang (68.4.115.53), 05/18/2015 00:50:18
1F:推 mingpepe: 感謝回答 05/18 02:46
2F:→ mingpepe: 雖然這規則將會被移除 但上一篇最下面從Spec中的例子 05/18 02:57
3F:→ mingpepe: 還是不太了解這個命名規則 05/18 02:58
可參考該 stackoverflow 連結;發問者有整理他的理解,底下 C# 大神 Eric Lippert 有更進一步解釋,以及他的 blog 專文
4F:→ GoalBased: 是說A大也寫C#嗎XD 05/18 09:16
是的 ※ 編輯: AmosYang (68.4.115.53), 05/18/2015 12:36:06







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Boy-Girl站內搜尋

TOP