public void SaveToFile(string directoryPath, string fileName, CourseReport report) { if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } File.WriteAllText(Path.Combine(directoryPath, fileName), report.ToString()); }
static void Main(string[] args) { var report = new CourseReport(); report.AddEntry(new CourseReportEntry { Name = "Patrones de diseño", Students = 1000, Rating = 5 }); report.AddEntry(new CourseReportEntry { Name = "Flutter", Students = 1900, Rating = 4.5 }); Console.WriteLine(report.ToString()); var saver = new FileSaver(); saver.SaveToFile(@"Reports", "WorkReport.txt", report); }