既然你所编写的代码,这里是什么,我看不出它的例子:
//going to set filesGroupList[x] to a string and then see what happens.
filesGroupList[x] = "First line of string.\nSecond line of string.\n";
//now we go into the using portion.
using (StringReader reader = new StringReader(filesGroupList[x]))
{
//reader has access to the whole string.
while ((filesGroupList[x] = reader.ReadLine()) != null)
{
//first time through, filesGroupList[x] is set to "First line of string."
//second time through, filesGroupLIst[x] is set to "Second line of string."
Console.WriteLine(filesGroupList[x]);
}
//third time through, ReadLine() returns null.
//filesGroupList[x] is set to null.
//Code breaks out of while loop.
Console.WriteLine(filesGroupList[x]); //outputs an empty line.
}
//outside of using, filesGroupList[x] still null.
Console.WriteLine(filesGroupList[x]); //also outputs an empty line.
现在,给我其他的答案,我建议使用线,我们就会把一切都相同,除了线部分。
//going to set filesGroupList[x] to a string and then see what happens.
filesGroupList[x] = "First line of string.\nSecond line of string.\n";
using (StringReader reader = new StringReader(filesGroupList[x]))
{
//reader has access to the whole string.
string line;
while ((line = reader.ReadLine()) != null)
{
//first time through, line is set to "First line of string."
//second time through, line is set to "Second line of string."
Console.WriteLine(line);
}
//third time through, ReadLine() returns null.
//line is set to null.
//filesGroupList[x] is still set to "First line of string.\nSecond line of string.\n"
Console.WriteLine(line); //outputs an empty line.
Console.Write(filesGroupList[x]); //outputs whole string (on 2 lines).
}
Console.WriteLine(line); //won't compile. line doesn't exist.
Console.Write(filesGroupList[x]); //outputs whole string (on 2 lines).
所以我不认为你想从filesGroupList[x]
读,然后存储在filesGroupList[x]
。如果filesGroupList[x]
字符串没有行尾字符,你干脆把这个字符串右后卫它(然后把null
在你下一次通过while
循环)。如果filesGroupList[x]
中的字符串确实有行尾字符,则每次通过while
循环时,都会将字符串的一部分放回filesGroupList[x]
,我不认为这是您的意图。
我不明白什么是你想acheive,它看起来非常奇怪 – nothrow 2013-03-08 16:46:36
我想读我的字符串具体的信息,但我会稍后再使用此字符串。 – inside 2013-03-08 16:49:35