>  기사  >  백엔드 개발  >  C#의 스트림 집합

C#의 스트림 집합

WBOY
WBOY앞으로
2023-08-23 08:17:05701검색

C#의 스트림 집합

문자열 배열 값 설정−

string[] names = new string[] {"Jack", "Tom"};

이제 foreach 배열을 사용하여 파일에 콘텐츠 쓰기−

using (StreamWriter sw = new StreamWriter("names.txt")) {

   foreach (string s in names) {
      sw.WriteLine(s);
   }
}

다음은 파일에 텍스트를 쓰기 위한 스트림 배열을 보여주는 예입니다−

예제

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();
      }
   }
}

위 내용은 C#의 스트림 집합의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제