Sunday, 29 May 2016

C# Program to Calculate Size of File using LINQ

using System;
using System.Linq;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        string[] MyFiles= Directory.GetFiles("c:\\xxx\\");
        var avg = MyFiles.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();
    }
}
---------------------------------------
OUTPUT:
The Average file size is 11.3 MB
-------------------------------------------

No comments:

Post a Comment