In most cases, this is bad practice. You are only reading, so why would you ever come back? Remember result of the first line reading and go forward. Actually, if the file is not too big, you can gain a lot if you read everything at once and then only manipulate the string, using
System.IO.StreamReader.ReadToEnd
:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx[
^].
Now, a couple of notes:
Your
FileName.ToString
tells me a lot. What, don't you see that the file name is already a string?
Also, this is not a good pattern of using the types like
StreamReader
. It implements
System.IDisposable
, so you can use it via the
using
statement (not to be confused with
using
declaration):
using (StreamReader reader = new StreamReader(@op.FileName.ToString())) {
}
Please see:
http://msdn.microsoft.com/en-us/library/system.idisposable.aspx[
^],
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx[
^].
—SA