In this article, learn how to Calculate the Size of a File using LINQ in C#.
C# Program to Calculate the Size of File using LINQ
This example shows how to Calculate the Size of a File using LINQ in C#s.
using System; using System.Linq; using System.IO; class Program { static void Main(string[] args) { string[] dirfiles = Directory.GetFiles("c:\\network\\"); var avg = dirfiles.Select(file =>new FileInfo(file).Length).Average(); avg = Math.Round(avg / 10, 1); Console.WriteLine("The Average file size is {0} MB",avg); Console.ReadLine(); }
– Article ends here –