- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to read all the lines of a file at once
Use ReadAllText() method to read all the lines of a file at once.
Let’s say we have a file “hello.txt” with the following lines −
One Two Three
To read the above file, add the path of the file as parameter.
File.ReadAllText(myPath);
Above, myPath had the file path.
String myPath = "hello.txt";
Let us see the complete code −
Example
using System; using System.IO; public class Demo { public static void Main() { String myPath = "hello.txt"; String allLines; allLines = File.ReadAllText(myPath); Console.WriteLine(allLines); } }
Output
The following is the output −
One Two Three
Advertisements