Saturday, 2 December 2017

C# Program to Calculate Size of File using LINQ


Code:

using System;
using System.Linq;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        string[] dirfiles = Directory.GetFiles("c:\\sri\\");
        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();
    }
}


Output:

The Average file size is 8.8 MB



More C# Programs:





















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...