Just use File.ReadLines which returns an IEnumerable<string>
and doesn’t load all the lines at once to the memory.
foreach (var line in File.ReadLines(_filePath))
{
//Don't put "line" into a list or collection.
//Just make your processing on it.
}
More Related Contents:
- How to flatten tree via LINQ?
- What ‘additional configuration’ is necessary to reference a .NET 2.0 mixed mode assembly in a .NET 4.0 project?
- How to abort a Task like aborting a Thread (Thread.Abort method)?
- What is the proper way to rethrow an exception in C#? [duplicate]
- Covariance and IList
- C# Create New T()
- .NET – What’s the best way to implement a “catch all exceptions handler”
- Troubleshooting BadImageFormatException
- How do I restart a WPF application? [duplicate]
- Simplest way to do a fire and forget method in c# 4.0
- Unblock File from within .net 4 c#
- Does a locked object stay locked if an exception occurs inside it?
- Is it possible to run a .NET 4.5 app on XP?
- Generics: casting and value types, why is this illegal?
- Active Directory COM Exception – An operations error occurred (0x80072020)
- How to avoid a System.Runtime.InteropServices.COMException?
- Image.FromStream() method returns Invalid Argument exception
- Best practices: throwing exceptions from properties
- Parallel.For(): Update variable outside of loop
- How to serialize an Exception object in C#?
- More Elegant Exception Handling Than Multiple Catch Blocks? [duplicate]
- ArgumentOutOfRangeException on initialized List
- How can I handle forms authentication timeout exceptions in ASP.NET?
- Exception.Message vs Exception.ToString()
- What is wrong with ToLowerInvariant()?
- Is there a built in .NET exception that indicates an illegal object state?
- In a .net Exception how to get a stacktrace with argument values
- Which exceptions shouldn’t I catch?
- Which types of exception not to catch?
- Dynamically changing Textbox’s AutoComplete List causes AccessViolationException, any advice?