要件の完全なセットは実際にはありませんが、ここにあります。
string[] fileAWords = File.ReadAllText("C:\\File - A.txt").Split(' ');
string[] fileBWords = File.ReadAllText("C:\\File - B.txt").Split(' ');
// The comparer makes it so the union is case insensitive
// For example: Welcome in File - A and welcome (lower-case) in File - B in a Union would both be in the result
// With the comparer, it will only appear once.
IEnumerable<string> allWords = fileAWords.Union(fileBWords, new StringEqualityComparer());
// We did the split on a space, so we want to put the space back in when we join.
File.WriteAllText("C:\\File - C.txt", string.Join(" ", allWords));
StringEqualityComparer クラスのコードは次のとおりです。
class StringEqualityComparer : IEqualityComparer<string>
{
// Lower-case your strings for a case insensitive compare.
public bool Equals(string s1, string s2)
{
if (s1.ToLower().Equals(s2.ToLower()))
{
return true;
}
else
{
return false;
}
}
#region IEqualityComparer<string> Members
public int GetHashCode(string s)
{
return s.GetHashCode();
}
#endregion
}