I currently have two arrays one the stores a file name and another that stores the file size. I need to show both the maximum file size and its name. I can get it to show the largest file by using this code.
long[] fileSize;
string[] fileName;
fileSize = new long[fileCount];
fileName = new string[fileCount];
for (int index = 0; index < files.Length; index++)
{
fileSize[index] = files[index].Length;
fileName[index] = files[index].Name;
}
long largestFile = fileSize.Max();
string latestFileName = fileName[fileSize.Max()];
Console.WriteLine("Total size of all files: {0}", totalSize);
Console.WriteLine("Largest file: {1}, {0}", largestFile, latestFileName );
I have tried using google but it just tells me how to work out the maximum or minimum.
There’s no need for separate arrays for the name and size, just loop over your
filesarray, and keep track of the current max file size and it’s name in separate variables. Something like this: