I'm taking a C# course, and the current assignment is to create a console application that transfers new files (modified in the last 24 hours) from directory "Customer Orders" to directory "Home Office".
At this point I'm just trying to come up with a way to figure out which files are new. To see if it works, I'm using Console.WriteLine to print new files to the console window. However, all it does is print "System.Linq.Enumerable+WhereArrayIterator'1[System.IO.FileInfo]".
I'm incredibly new to this language, and I'm worried I'm already going about everything the wrong way. Here is my code so far (after an hour of googling and getting ideas from StackOverflow):
class ModifiedFiles
{
public string your_dir;
public IEnumerable<FileInfo> modified()
{
your_dir = @"C:\Users\Student\Desktop\Customer Orders";
var directory = new DirectoryInfo(your_dir);
DateTime from_date = DateTime.Now.AddDays(-1);
DateTime to_date = DateTime.Now;
var files = directory.GetFiles()
.Where(file => file.LastWriteTime >= from_date && file.LastWriteTime <= to_date);
return files;
}
}
static void Main(string[] args)
{
ModifiedFiles newFiles = new ModifiedFiles();
Console.WriteLine(newFiles.modified());
Console.ReadLine();
}
Can someone kindly point out what is happening here and set me on the right track?
What happens is that every type in C# do inherit the
ToString
method, which unless overriden will print a default string-representation of the object: its name type.Reference:
https://msdn.microsoft.com/en-us/library/system.object.tostring(v=vs.110).aspx
Now here are 4 examples, printing out every file name, and showing the default behavior of
ToString
and an overridden behavior: