A set of streams in C#
Aug 23, 2023 am 08:17 AMSet the value of the string array−
string[] names = new string[] {"Jack", "Tom"};
Now use the foreach array to write the content in the file−
using (StreamWriter sw = new StreamWriter("names.txt")) { foreach (string s in names) { sw.WriteLine(s); } }
Here is an example, Displays an array of streams used to write text to a file −
Example
using System; using System.IO; namespace FileApplication { class Program { static void Main(string[] args) { string[] names = new string[] {"Jack", "Tom"}; using (StreamWriter sw = new StreamWriter("names.txt")) { foreach (string s in names) { sw.WriteLine(s); } } // Read and show each line from the file. string line = ""; using (StreamReader sr = new StreamReader("names.txt")) { while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } } Console.ReadKey(); } } }
The above is the detailed content of A set of streams in C#. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the alternatives to NULL in C language

Method of copying code by C language compiler

What are the web versions of C language compilers?

Is NULL still important in modern programming in C language?

C language online programming website C language compiler official website summary

C language compiler installation tutorial (computer version)
