Example:
variable = new StreamReader( file ).ReadToEnd();
Is that acceptable?
You need to Dispose of objects that implement IDisposable
. Use a using
statement to make sure it gets disposed without explicitly calling the Dispose method.
using (var reader = new StreamReader(file))
{
variable = reader.ReadToEnd();
}
Alternately, use File.ReadAllText(String)
variable = File.ReadAllText(file);