I've instanced a FileInfo[] object like so:
Then I want to do a switch statement depending upon how many filenames matching the pattern were found:
I'm having a problem figuring out the foreach portion for the default case. What I want to do is iterate all members of the fileInfo instance, and add the fileInfo.Names to a class property (probably a typed list). And I'd like to avoid having to create another FileInfo object if possible.
In googling I've come across several examples like
but none for an already instanced FileInfo object.
Thanks!
Code:
FileInfo[] fileInfo = directoryInfo.GetFiles(fileNamePattern);
Then I want to do a switch statement depending upon how many filenames matching the pattern were found:
Code:
switch (fileInfo.Count())
{
case 0: //No matches
return null;
case 1: //Unique fileNamePattern match
this.FileNameMatchFound = true;
fileNameMatch = fileInfo[0].Name;
return fileNameMatch;
default:
{
foreach (fileInfo...?)
}
}
I'm having a problem figuring out the foreach portion for the default case. What I want to do is iterate all members of the fileInfo instance, and add the fileInfo.Names to a class property (probably a typed list). And I'd like to avoid having to create another FileInfo object if possible.
In googling I've come across several examples like
Code:
foreach (FileInfo f in dir.GetFiles())
...
but none for an already instanced FileInfo object.
Thanks!