From 73bf46712d4f18a843b4b6676dfc0a3b1761d3e9 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Tue, 23 Feb 2021 16:37:53 +1100 Subject: [PATCH] Finished Writing a Report with LINQ --- Introduction/Introduction/Program.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Introduction/Introduction/Program.cs b/Introduction/Introduction/Program.cs index ca3ea61..eb90722 100644 --- a/Introduction/Introduction/Program.cs +++ b/Introduction/Introduction/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; namespace Introduction { @@ -10,6 +11,20 @@ namespace Introduction { string path = Directory.GetCurrentDirectory(); ShowLargeFilesWithoutLinq(path); + + Console.WriteLine("***"); + ShowLargeFilesWithLinq(path); + } + + private static void ShowLargeFilesWithLinq(string path) + { + var query = new DirectoryInfo(path).GetFiles() + .OrderBy(f => f.Length) + .Take(5); + foreach (var file in query.Take(5)) + { + Console.WriteLine($"{file.Name,-50} : {file.Length,10:N0}"); + } } private static void ShowLargeFilesWithoutLinq(string path)