
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Write an Array to a File
Use WriteAllLines method to write an array to a file.
Firstly, set a string array −
string[] stringArray = new string[] { "one", "two", "three" };
Now, use the WriteAllLines method to add the above array to a file −
File.WriteAllLines("new.txt", stringArray);
Here is the complete code −
Example
using System.IO; using System; public class Program { public static void Main() { string[] stringArray = new string[] { "one", "two", "three" }; File.WriteAllLines("new.txt", stringArray); using (StreamReader sr = new StreamReader("new.txt")) { string res = sr.ReadToEnd(); Console.WriteLine(res); } } }
Output
one two three
Advertisements