Reputation: 237
What is the difference between using File from using System.IO
& StreamWriter
from using System.IO
?
I am using File.WriteAllLines
but in many internet-source-codes they are using:
using (StreamWriter writer = new StreamWriter("important.txt"))
{
writer.Write("Word ");
}
Upvotes: 1
Views: 1082
Reputation: 5514
File.WriteAllLines
is simply a convenience method that internally uses a StreamWriter
, which in turn uses a FileStream
to write to the file.
The main difference is that while File.WriteAllLines
only writes to files, a StreamWriter
can write to any stream, for example a network stream.
Either way works, use what suits you the best.
Upvotes: 4