Answers for "open file and read all lines c#"

C#
3

c# read file by line

using (var file = new StreamReader(fileName)) {
	string line;
	while((line = file.ReadLine()) != null)  
	{  
		System.Console.WriteLine(line);
	}  
}
Posted by: Guest on July-28-2021
0

c# read all lines from filestream

public IEnumerable<string> ReadLines(Func<Stream> streamProvider,
                                     Encoding encoding)
{
    using (var stream = streamProvider())
    using (var reader = new StreamReader(stream, encoding))
    {
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            yield return line;
        }
    }
}
Posted by: Guest on February-21-2020

Code answers related to "open file and read all lines c#"

C# Answers by Framework

Browse Popular Code Answers by Language