How to read the complete content of the Text File in C#?

Here’s an easy way to read the complete content of the text file in c# with just one line of code. This is achieved using the System.IO.File.ReadAllText function.

Below is a sample code snippet demonstrating how to read the complete content of the Text File in C#? The test1.txt contains the file which needs to be displayed. The test1.txt contains the text “Welcome to Abundantcode.com”.

How to read the complete content of the Text File in C#?

using System;

using System.Collections.Generic;

using System.Data;

namespace AbundantCode

{

internal class Program

{

//How to read the complete content of the TextFile in C# ?

private static void Main(string[] args)

{

string Result = System.IO.File.ReadAllText("test1.txt");

Console.WriteLine(Result);

Console.ReadLine();

}

}

}
How to read the complete content of the Text File in C#?