作者LetsGoToEat (一起去吃东西吧)
看板C_Sharp
标题Re: [问题] 变数宣告在if结构里
时间Sun May 18 14:30:51 2014
※ 引述《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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1400394654.A.C27.html