This file contains hidden or 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
| //If-Else Approach | |
| public static class ParserFactory | |
| { | |
| public static IFileParser Create(string filename) | |
| { | |
| var extension = Path.GetExtension(fileName); | |
| if (extension == ".json") | |
| { | |
| return new JsonParser(); |
This file contains hidden or 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.Threading; | |
| static class Program { | |
| static void Main() { | |
| Console.Write("Performing some task... "); | |
| using (var progress = new ProgressBar()) { | |
| for (int i = 0; i <= 100; i++) { | |
| progress.Report((double) i / 100); |
This file contains hidden or 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
| Task.Run(ProcessWriteAsync); // main function call | |
| async Task ProcessWriteAsync() | |
| { | |
| string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; | |
| string subPath = @"logs\"; | |
| string fileName = $@"chatlogs.txt"; | |
| DirectoryInfo directoryInfo = new(baseDirectory); |
OlderNewer