Re: [問題] 變數宣告在if結構裡

看板C_Sharp作者 (一起去吃東西吧)時間10年前 (2014/05/18 14:30), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/5 (看更多)
※ 引述《GoalBased (Artificail Intelligence)》之銘言: : 大概是長這樣,細節有錯的話自己改, : 是說..現在的新手會開檔讀檔,會用類別,不會用function是怎麼回事= = 感謝幫忙,我試著改成這樣 private void button1_Click(object sender, EventArgs e) { System.IO.StreamReader file = new System.IO.StreamReader("file.txt"); string str = file.ReadLine(); if (str == "father") { ClassFather xxx = new ClassFather(); IamFunction(file, xxx); } else if (str == "son") { ClassSon xxx = new ClassSon(); IamFunction(file, xxx); } } private void IamFunction(System.IO.StreamReader file, ClassFather xxx) { xxx.strA = file.ReadLine(); xxx.strB = file.ReadLine(); } 似乎是可以了@@ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.69.93.23 ※ 文章網址: http://www.ptt.cc/bbs/C_Sharp/M.1400394654.A.C27.html
文章代碼(AID): #1JU5EUmd (C_Sharp)
文章代碼(AID): #1JU5EUmd (C_Sharp)