, Except :
var files = sourceFilenameList.Except(destinationList);
, , , , : new[] {a, a, b, b, c}.Except(new[] {b, c}) - {a}, {a, a}.
LINQ, IEnumerable<T> - , List, ToList:
var files = sourceFilenameList.Except(destinationList).ToList();
EDIT: , , FileList, , . Equals GetHashCode (, , IEquatable<FileList>), IEqualityComparer<T>. : FileNames , . , . . - :
public sealed class FileList : IEquatable<FileList>
{
private readonly string fileNames;
public string FileNames { get { return fileNames; } }
public FileList(string fileNames)
{
if (fileNames == null)
{
throw new ArgumentNullException("fileNames");
}
this.fileNames = fileNames;
}
public override int GetHashCode()
{
return fileNames.GetHashCode();
}
public override bool Equals(object other)
{
return Equals(other as FileList);
}
public bool Equals(FileList other)
{
return other != null && other.FileNames == FileNames;
}
}
:
List<FileList> sourceFileNames = new List<FileList>
{
new FileList("1.txt"),
new FileList("2.txt"),
new FileList("3.txt"),
new FileList("4.txt")
};
List<FileList> destinationFileNames = new List<FileList>
{
new FileList("1.txt"),
new FileList("2.txt")
};
IEnumerable<FileList> except = sourceFileNames.Except(destinationFileNames);