Created
September 4, 2020 13:16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Collections.Generic; | |
namespace FileHandles | |
{ | |
public class DataWriter | |
{ | |
public StreamWriter OpenFile(string fileName) | |
{ | |
return new StreamWriter(fileName); | |
} | |
public bool WriteData(StreamWriter writer, List<string> data) | |
{ | |
foreach (var line in data) | |
{ | |
writer.WriteLine(line); | |
} | |
return true; | |
} | |
public bool CloseFile(StreamWriter writer) | |
{ | |
writer.Close(); | |
writer.Dispose(); | |
return true; | |
} | |
} | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var dataWriter = new DataWriter(); | |
var writer = dataWriter.OpenFile("data.txt"); | |
var lines = new List<string> | |
{ | |
"This is the first string.", | |
"Another string that needs writing.", | |
"Yet another string for writing." | |
}; | |
var result = dataWriter.WriteData(writer, lines); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment