■ StreamWriter 클래스를 사용해 콘솔에 출력하는 방법을 보여준다.
▶ StreamWriter 클래스 : 콘솔 출력하기 예제 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using System.IO; using(StreamWriter wrtier = GetConsoleStreamWriter()) { DirectoryInfo sourceInfo = new DirectoryInfo(@"c:\windows"); DirectoryInfo[] directoryInfoArray = sourceInfo.GetDirectories("s*", SearchOption.TopDirectoryOnly); foreach(DirectoryInfo info in directoryInfoArray) { wrtier.WriteLine(info.Name); } } |
▶ StreamWriter 클래스 : 콘솔 출력하기 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System; using System.IO; #region 콘솔 출력 스트림 라이터 구하기 - GetConsoleStreamWriter() /// <summary> /// 콘솔 출력 스트림 라이터 구하기 /// </summary> /// <returns>콘솔 출력 스트림 라이터</returns> public StreamWriter GetConsoleStreamWriter() { StreamWriter writer = new StreamWriter(Console.OpenStandardOutput()); Console.SetOut(writer); return writer; } #endregion |