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

作者: LetsGoToEat (一起去吃東西吧)   2014-05-18 14:30:51
※ 引述《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();
}
似乎是可以了@@

Links booklink

Contact Us: admin [ a t ] ucptt.com