I have two List<FileInfo>
and I want to return the common FileItem
between them.
List<FileInfo> outputList = new List<FileInfo>();
outputList = list1.Intersect(list2).ToList();
However, I'm getting back an empty List.
Both the lists contain FileInfo
's found by
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
IEnumerable<System.IO.FileInfo> fileList =
dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
And filtered by queries.
FileInfo
does not overrideObject.Equals
so different instances will not be equal even if they refer to the same file. You will have to provide your ownIEqualityComparer<FileInfo>
to do the comparison. – Suppository