This C# Program Calculates Size of File using LINQ. Here the size of the folder is found using LINQ functions.
Here is source code of the C# Program to Calculate Size of File using LINQ. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/*
* 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[] 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();
}
}
Here is the output of the C# Program:
The Average file size is 8.8 MB
Good readers always drop comments!!