mithi

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.
  1. /*
  2.  * C# Program to Calculate Size of File using LINQ
  3.  */
  4. using System;
  5. using System.Linq;
  6. using System.IO;
  7. class Program
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         string[] dirfiles = Directory.GetFiles("c:\\sri\\");
  12.         var avg = dirfiles.Select(file =>new FileInfo(file).Length).Average();
  13.         avg = Math.Round(avg / 10, 1);
  14.         Console.WriteLine("The Average file size is {0} MB",avg);
  15.         Console.ReadLine();
  16.     }
  17. }
advertisements
Here is the output of the C# Program:
The Average file size is 8.8 MB

0 comments:

Post a Comment

 
Top
Mithilesh Joshi