I have a generic Print
method that iterates over a list and simply prints each item's file name
private static void Print<T>(
Func<IEnumerable<T>> getFiles, Func<T, string> getFileName)
where T : class
{
foreach (T file in getFiles())
{
var fileName = getFileName(file);
Console.WriteLine("File Name: {0}", fileName);
}
}
For the method to know what the type of T
is I can call Print
in two different ways
Print<FileInfo>(FileFinder.GetFiles, fileInfo => fileInfo.FullName);
-- or --
Print(FileFinder.GetFiles, (FileInfo fileInfo) => fileInfo.FullName);
What would be a correct way to call Print
method?
Specify generic type explicitly or let the compiler infer it?