Users Online

· Guests Online: 151

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Calculate the Size of File using LINQ

C# Program to Calculate the Size of File using LINQ

 

 

This is a C# Program to calculate size of file using linq.

Problem Description

This C# Program Calculates Size of File using LINQ.

Problem Solution

Here the size of the folder is found using LINQ functions.

Program/Source Code

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.

/*
 * C# Program to Calculate Size of File using LINQ
 */
using System;
using System.Linq;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        string[] dirfiles = Directory.GetFiles("c:\\sri\\");
        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();
    }
}
Program Explanation

This C# program used to calculate size of file using LINQ. LINQ (Language Integrated Query) is uniform query syntax used to save and retrieve data from different sources. It is integrated thereby eliminating the mismatch between programming languages and databases, as well as providing a single querying interface for different types of data sources.

 

The size of the folder is found using LINQ functions. Create the files from directory using ‘dirfiles’ variable, the length() function is used to compute the size of the file. Using Round() function compute the division of the value of ‘avg’ variable by 10. Print the size of file.

Runtime Test Cases
 
The Average file size is 8.8 MB

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.01 seconds
10,812,729 unique visits