Q:

Write a program in C# Sharp to calculate size of file using LINQ

0

Write a program in C# Sharp to calculate size of file using LINQ. 
Expected Output :
The Average file size is 3.4 MB

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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();
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now