Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have BOLDED where the errors occur. I will display the error messages below. E

ID: 3555520 • Letter: I

Question

I have BOLDED where the errors occur. I will display the error messages below.

Error   1   'System.IO.Directory' does not contain a definition for 'exists'

Error   2   Cannot implicitly convert type 'int' to 'bool'  

Error   3   Property or indexer 'System.Array.Length' cannot be assigned to -- it is read only  

Error   4   'System.IO.File' does not contain a definition for 'GetCreationtime'  

Error   5   'System.IO.File' does not contain a definition for 'GetLastAccesstime'  

using System;
using System.IO;
class DebugFourteen1
{
   static void Main()
   {
      string fileName;
      string directory;
      string path;
      string[] files;
      int x;
      Console.Write("Enter a directory ");
      directory = Console.ReadLine();
      if(Directory.exists(directory))
      {
          files = Directory.GetFiles(directory);
          if(files.Length = 0)
              Console.WriteLine("There are no files in " + directory);
          else
          {
             Console.WriteLine(directory + " contains the following files");
             for(x = 0; x < 20; ++x)
                 Console.WriteLine(" " + files[x]);
             Console.Write(" Enter a file name ");
             fileName = Console.ReadLine();
             path = directory + "\" + fileName;
             if(File.Exists(path))
             {
                Console.WriteLine(" File exists and was created " + File.GetCreationTime(path));
                Console.WriteLine("File was created " +
                File.GetCreationtime(fileName));
                Console.WriteLine("File was last accessed " +
                File.GetLastAccesstime(fileName));
                Console.WriteLine("File was last written to " +
                File.GetLastWriteTime(fileName));
             }
             else
                 Console.WriteLine(" " + fileName + " does not exist in the " + directory + " directory");
           
         }
      }
      else
      {
          Console.WriteLine("Directory " + directory + " does not exist");
      }
}
}

Explanation / Answer

1)Error   1   'System.IO.Directory' does not contain a definition for 'exists'

E should be in Capitals and argument of Exists method has to be path

2)Cannot implicitly convert type 'int' to 'bool'  

if(files.Length = 0) should be changed to if(files.Length == 0)

3)Property or indexer 'System.Array.Length' cannot be assigned to -- it is read only  

same as 2

4)System.IO.File' does not contain a definition for 'GetCreationtime'  

Again it should be GetCreationTime

5) 'System.IO.File' does not contain a definition for 'GetLastAccesstime'  

should be GetLastAccessTime