Looking at some old code I wrote a few years ago, I noticed something I missed. I don't think this should work, but it does.
In the code below, I use ref in the first call, but do NOT use it in the second call. However, the ref still gets passed and the listFiles is passed all the way back to the original call.
Is this correct?
private void TopLayer( DirectoryInfo dirInfo )
{
List<string> listFiles = new List<string>();
GetFileList( ref listFiles, dirInfo );
Console.WriteLine( listFiles.Count.ToString() );
}
private void GetFileList( ref List<string> listFiles, DirectoryInfo dirInfo )
{
ActuallyGetFileList( listFiles, dirInfo );
}
private void ActuallyGetFileList( List<string> listFiles, DirectoryInfo dirInfo )
{
FileInfo[] newfileinfo = dirInfo.GetFiles();
// code here to to go from the array to the list
// newfileinfo array to List<string> listFiles
}
Since I did not use ref in the second call, I don't think it should have returned the list of files.