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