From d13bc6b34d09b98c1197b4aa723fb9f1e51b64d4 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Tue, 23 Feb 2021 16:32:29 +1100 Subject: [PATCH] Finished Writing a Report without LINQ --- Introduction/Introduction.sln | 25 +++++++++++++ Introduction/Introduction/Introduction.csproj | 8 ++++ Introduction/Introduction/Program.cs | 37 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 Introduction/Introduction.sln create mode 100644 Introduction/Introduction/Introduction.csproj create mode 100644 Introduction/Introduction/Program.cs diff --git a/Introduction/Introduction.sln b/Introduction/Introduction.sln new file mode 100644 index 0000000..ba8d086 --- /dev/null +++ b/Introduction/Introduction.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30907.101 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Introduction", "Introduction\Introduction.csproj", "{53450129-90CC-4C40-BDB3-295F60669012}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {53450129-90CC-4C40-BDB3-295F60669012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {53450129-90CC-4C40-BDB3-295F60669012}.Debug|Any CPU.Build.0 = Debug|Any CPU + {53450129-90CC-4C40-BDB3-295F60669012}.Release|Any CPU.ActiveCfg = Release|Any CPU + {53450129-90CC-4C40-BDB3-295F60669012}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3A6B85BA-05FF-44DA-B35D-12FDDCF35AC7} + EndGlobalSection +EndGlobal diff --git a/Introduction/Introduction/Introduction.csproj b/Introduction/Introduction/Introduction.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Introduction/Introduction/Introduction.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Introduction/Introduction/Program.cs b/Introduction/Introduction/Program.cs new file mode 100644 index 0000000..ca3ea61 --- /dev/null +++ b/Introduction/Introduction/Program.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace Introduction +{ + class Program + { + static void Main(string[] args) + { + string path = Directory.GetCurrentDirectory(); + ShowLargeFilesWithoutLinq(path); + } + + private static void ShowLargeFilesWithoutLinq(string path) + { + DirectoryInfo directory = new DirectoryInfo(path); + FileInfo[] files = directory.GetFiles(); + Array.Sort(files, new FileInfoComparer()); + + for (int i = 0; i < 5; i++) + { + FileInfo file = files[i]; + Console.WriteLine($"{file.Name, -20} : {file.Length, 10:N0}"); + } + } + + } + + public class FileInfoComparer : IComparer + { + public int Compare(FileInfo x, FileInfo y) + { + return y.Length.CompareTo(x.Length); + } + } +}