循环初始化多个streamwriter
本文关键字:streamwriter 初始化 循环 | 更新日期: 2023-09-27 18:12:21
我想做如下的事情:
int loopCount = 0;
while (loopCount != 18)
{
StreamWriter DBSplit + loopCount =
new StreamWriter(@"L:'BananaDB'DBFILE" + loopCount + ".txt");
loopCount++;
}
最好的方法是什么?目前的问题是"DBSplit + loopCount"
。虽然是的,这是因为我试图添加一个int到StreamWriter变量,我不能使用字符串。有解决办法吗?
使用数组?也可以用for
循环替换while
:
var writers = new StreamWriter[18];
for(int i =0; i<18; i++)
writers[i] = new StreamWriter(@"L:'BananaDB'DBFILE" + i + ".txt");