看板 GameDesign 關於我們 聯絡資訊
namespace Console_Wars { class Hero (第一個class) { . . public void showLower2 () {..} . . string lower_2; <- in class Hero } public void showLower1 () {..} string lower_1; <- global //console程式 class Program (第二個class) { . . static void Main(string[] args) { . . string lower = HeroA.name.ToLower(); HeroA.showLower2(); (主要問題點) showLower1 (); . . } <- local var lower 消滅 } 1.Hero::showLower2是宣告於class Hero中,只看的到class自己的Hero::lower_2 2.Console_Wars::showLower1也只能秀Console_Wars::lower_1 <- global 至於你在Main裡面宣告的local var lower,1跟2都看不到 namespace Console_Wars { class Heros () { public void showlower () { Console.WriteLine (name.ToLower ()); } } public void showlower (string Name) <-將name當成function變數帶進來 { Console.WriteLine = (Name.ToLower()); } . . static void Main(string[] args) { . . showlower (HeroA.name) <-呼叫function,並且把變數帶進去 HeroA.showlower () <-直接使用class的func . . } } ___ 因為我沒玩過C#,不知道概念跟C會不會有太大出入,有錯請指正 問題應該在,你還沒有 變數範圍的概念? (variable scope) 不過function概念的話,可以直接丟值進來就解決了,沒有必要堅持用已有var 或是直接在class裡面做完 Heros::showlower,直接當成class 的東西使用 -- 明知道這是不可能的願望 卻如同烙印的爪痕沁入大地 假如 可以實現的話 將我的存在剝奪 捨棄也無妨 祈禱著 祈求著 幻想也好 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.182.68 ※ 文章網址: https://www.ptt.cc/bbs/GameDesign/M.1487040599.A.0E6.html ※ 編輯: LayerZ (60.251.182.68), 02/14/2017 10:59:59
anterior: 非常感謝您的指導 02/14 11:00
anterior: 最後面您說的對,由於我剛開始學 02/14 11:01
anterior: 因此會想要將學過的或是還沒有學過的 02/14 11:02
anterior: 自己嘗試排列組合,可以順便釐清結構 02/14 11:02
anterior: 而且在Visual自帶的報錯部分也學習到蠻多的 02/14 11:03
anterior: 不過目前遇到比較多的問題是 02/14 11:05
anterior: 我學會的function還不多 02/14 11:05
anterior: 因此時常遇到不知是結構的問題 02/14 11:06
anterior: 抑或者是這個function無法這樣使用 02/14 11:06
anterior: 因此我現在會先在學習更多的function後 02/14 11:06
anterior: 再來慢慢自己研究嘗試 02/14 11:07
anterior: 非常感謝各位的指導^_^ 02/14 11:07
LayerZ: ...怎麼看完有點擔心阿XDD 02/14 11:08
LayerZ: function就是function,懂概念的話,什麼函式都一樣阿XD 02/14 11:09
LayerZ: 不過就多try吧=w= 02/14 11:10
anterior: 噗... 我會時常來向版上的前輩們來報告進度的 02/14 11:10
supertyphoon: 企劃基本上就是各領域都要有像LayerZ這樣的分析能力 02/15 13:00
supertyphoon: 各領域就算沒比該專業強 如果能撐到該領域閉嘴就行 02/15 13:03