G
Gigs_
public class StreamsIOApp
{
[STAThread]
public static void Main(string[] args)
{
// create, write, close, open, read, close
byte[] buf1 = new Byte[]
{76,101,116,32,116,104,101,114,101,
32,98,101,32,108,105,103,104,116};
FileStream s = new FileStream(
"Foo.txt", FileMode.Create);
s.Write(buf1, 0, buf1.Length);
s.Close();
s = new FileStream(
"Foo.txt", FileMode.Open);
int i;
string str = "";
if (s.CanRead)
{
for (i = 0; (i = s.ReadByte()) != -1; i++)
{
str += (char)i;
}
}
s.Close();
Console.WriteLine(str);
Console.WriteLine(i);
}
}
why this for loop cant be like this?
for (i = s.ReadByte(); i != -1; i++)
{
str += (char)i;
}
thanks!
{
[STAThread]
public static void Main(string[] args)
{
// create, write, close, open, read, close
byte[] buf1 = new Byte[]
{76,101,116,32,116,104,101,114,101,
32,98,101,32,108,105,103,104,116};
FileStream s = new FileStream(
"Foo.txt", FileMode.Create);
s.Write(buf1, 0, buf1.Length);
s.Close();
s = new FileStream(
"Foo.txt", FileMode.Open);
int i;
string str = "";
if (s.CanRead)
{
for (i = 0; (i = s.ReadByte()) != -1; i++)
{
str += (char)i;
}
}
s.Close();
Console.WriteLine(str);
Console.WriteLine(i);
}
}
why this for loop cant be like this?
for (i = s.ReadByte(); i != -1; i++)
{
str += (char)i;
}
thanks!