You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
681 B
C#

using System;
using System.Linq;
using System.IO;
class LinqExercise16
{
static void Main(string[] args)
{
string[] dirfiles = Directory.GetFiles("/home/w3r/abcd/");
// there are three files in the directory abcd are :
// abcd.txt, simple_file.txt and xyz.txt
Console.Write("\nLINQ : Calculate the Size of File : ");
Console.Write("\n------------------------------------\n");
var avgFsize = dirfiles.Select(file =>new FileInfo(file).Length).Average();
avgFsize = Math.Round(avgFsize / 10, 1);
Console.WriteLine("The Average file size is {0} MB",avgFsize);
Console.ReadLine();
}
}