C# Program to Calculate the Size of File using LINQ

In this article, learn how to Calculate the Size of a File using LINQ in C#.


C# Program to Calculate the Size of File using LINQ

This example shows how to Calculate the Size of a File using LINQ in C#s.


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


– Article ends here –

If you have any questions, please feel free to share your questions or comments on the comment box below.

Share this:
We will be happy to hear your thoughts

      Leave a reply

      www.troubleshootyourself.com
      Logo