C# SystemIOFileReadAllLines() method

C# SystemIOFileReadAllLines() method C# System.IO.File.ReadAllLines() method

File.ReadAllLines method returns an array of strings containing lines of the file. It's not good idea to load entire file in memory, as resources are limited. Here we will see program that reads all lines in file and returns collection of strings.

C# File ReadAllLines method

using System;
namespace Csharp.ReadFile.Line.By.Line.Example
class Program
static void Main(string[] args)
foreach (string line in System.IO.File.ReadAllLines(@"C:\xxx\ReadMe.txt"))

VB.net File RealAllLines example

Here is Vb.net code snippet which uses static ReadAllLines method of File class.

Namespace Csharp.ReadFile.Line.By.Line.Example
Class Program
Private Shared Sub Main(args As String())
For Each line As String In System.IO.File.ReadAllLines("C:\xxx\ReadMe.txt")
End Sub
End Class
End Namespace

Description: The static method ReadAllLines of File class returns collection of strings in terms of array. We are iterating that array with the help of foreach line.


C# Parse method of DateTimeC# ArrayList Search using Linq Extension OfType MethodC# foreach loopc# arraylistc# stringC# DateTime DifferenceC# XML XmlReaderThreading in C#C# Binary To StringC# File ExistsC# Regular Expression Get Text Between Brackets


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.