Saturday, August 20, 2016

LINQ Calculate Average File Size in Folder C#-Example

LINQ Calculate Size of Folder


LINQ is language integrated query which allow programmers to query various objects without worrying about underlying implementations of these objects.


Below C# Program Calculates average file Size of folder using LINQ. In other words the average size of file in a folder is found using LINQ functions.



using System;
using System.IO;
using System.Linq;

namespace Zappmania.Example.LINQ.GetAverageFileSize


public class Program

public static void Main(string[] args)

var destPath = @"c:\\Zappmania\\";
var dirfiles = Directory.GetFiles(destPath);
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();







LINQ Calculate Average File Size in Folder C#-Example

No comments:

Post a Comment