Read a text file with LINQ in CSharp
Description
The following code shows how to read a text file with LINQ.
Example
/*from ww w.ja v a 2 s . com*/
using System;
using System.IO;
using System.Linq;
class Program
{
static string dataPath = @"Main.cs";
static void Main(string[] args)
{
var text = from line in File.ReadLines(dataPath)
where (line.Contains("a"))
select line;
File.WriteAllLines(@"data.txt", text);
}
}