G
Guest
I am reading the MCTS Exam 70-536 book by Nortrop and Wildermuth. Chapter 4
discusses the IEQualityComparer interface, and shows how to use it for a
HashTable. The August06 MSDN docs also show a similar example. In these
examples the class used for the IEQualityComparer has a
CaseInsensitiveComparer field. I found that when calling the
CaseInsensitiveComparer in the Equals method that it just calls the CompareTo
method in the class that I am using for the key of my HashTable. So, I am
wondering what CaseInsensitiveComparer is supposed to do if it really just
calls your own method to do the compare.
In my method I use one of the String.Toxxxxx methods (like
ToLowerInvariant()), which is new for .NET 2.0. So, I modified my Equals
method to just directly call my CompareTo method and not use
CaseInsensitiveComparer at all. It has the same result.
So, it looks like CaseInsensitiveComparer is obsolete, but is still
supported to not break older code, even though it now requires your key class
to implement IComparable to provide the CompareTo method, that would use one
of the new String.Toxxxx methods to do the actual case insensitive comparison
using a cultureinfo.
The book and MSDN help files make no mention of the things I found (the hard
way of course).
A secondary question, that then just naturally occurs to me, is "Why is
Microsoft's documentation and MSPress books so bad when it comes to helping
people learn .NET 2.0???" The book contains MANY more errors, and there is
nothing available from MS to help anyone. There is no way you could learn
this from the MSDN stuff, which is geared towards helping developers remember
how to use it than to teach them in the first place? Why would MS invest
billions to develop .NET and yet refuse to spend thousands to make it easier
for people to learn and understand?
Oh, and I think they should stop forcing their programmers (like Tony
Northrop) to write books, unless they are going to fully support that effort.
Free advice: pay Jeff Richter what ever he wants to write updated books that
fully cover .NET 2.0!
discusses the IEQualityComparer interface, and shows how to use it for a
HashTable. The August06 MSDN docs also show a similar example. In these
examples the class used for the IEQualityComparer has a
CaseInsensitiveComparer field. I found that when calling the
CaseInsensitiveComparer in the Equals method that it just calls the CompareTo
method in the class that I am using for the key of my HashTable. So, I am
wondering what CaseInsensitiveComparer is supposed to do if it really just
calls your own method to do the compare.
In my method I use one of the String.Toxxxxx methods (like
ToLowerInvariant()), which is new for .NET 2.0. So, I modified my Equals
method to just directly call my CompareTo method and not use
CaseInsensitiveComparer at all. It has the same result.
So, it looks like CaseInsensitiveComparer is obsolete, but is still
supported to not break older code, even though it now requires your key class
to implement IComparable to provide the CompareTo method, that would use one
of the new String.Toxxxx methods to do the actual case insensitive comparison
using a cultureinfo.
The book and MSDN help files make no mention of the things I found (the hard
way of course).
A secondary question, that then just naturally occurs to me, is "Why is
Microsoft's documentation and MSPress books so bad when it comes to helping
people learn .NET 2.0???" The book contains MANY more errors, and there is
nothing available from MS to help anyone. There is no way you could learn
this from the MSDN stuff, which is geared towards helping developers remember
how to use it than to teach them in the first place? Why would MS invest
billions to develop .NET and yet refuse to spend thousands to make it easier
for people to learn and understand?
Oh, and I think they should stop forcing their programmers (like Tony
Northrop) to write books, unless they are going to fully support that effort.
Free advice: pay Jeff Richter what ever he wants to write updated books that
fully cover .NET 2.0!