看这个例子,呵呵。VS2008,编译通过的。显示TRUE。注意我在函数中的处理:不但忽略大小写,而且忽略首尾的空格。 public class CompareOnly : IEqualityComparer<string> { public int GetHashCode(string t) { return t.GetHashCode(); } public bool Equals(string x, string y) { return x.Trim().ToUpper() == y.Trim().ToUpper(); } } class Program { static void Main(string[] args) { string[] s = new string[] { "abc", "def", "iLoVeU" }; CompareOnly co = new CompareOnly(); bool r = s.Contains("iloveu", co); Console.WriteLine(r.ToString()); Console.ReadKey(); } }
public class CompareOnly : IEqualityComparer<string>
{
public int GetHashCode(string t)
{
return t.GetHashCode();
} public bool Equals(string x, string y)
{
return x.Trim().ToUpper() == y.Trim().ToUpper();
}
} class Program
{ static void Main(string[] args)
{
string[] s = new string[] { "abc", "def", "iLoVeU" };
CompareOnly co = new CompareOnly();
bool r = s.Contains("iloveu", co);
Console.WriteLine(r.ToString());
Console.ReadKey();
}
}