[Mono-dev] DataTable Select string comparison patch

Jarosław Pawlak jarek.pawlak at gmail.com
Mon Dec 4 15:07:20 EST 2006

Hello, Konstantin

>  1. If one object is string = "5 " and the second object is Int32 = 5. Will
> the objects be equal?
No, they won't even go into the "if" because o1 is string, but o2 is not string
>  2. What if a case insensitive comparison should be done, but the objects
> are not strings? (May be type conversion should be done before the test 'o1
> is string').
Here we have two problems. One is i don't know what object can be case
sensitive or case insensitive if this object is not a string.  Numbers
don't differ lowcase or hicase, date objects will be equal/different
whenever we compare them after converting to string and making
tolower. And some custom objects can override CompareTo method.
Second problem is I didn't do the ToLower conversion (I'm not the
author of caseInsensitive comparation). I only added the TrimEnd to
existing patch which contained the ToLower method. I have put my patch
inside existing because I didn't want to do the "if (o is string )"
and casting object to string twice. And yes, before patch, a
caseSensitive test was done also only for strings.

>  3. Trimming + converting to low case are very expensive operations. Can you
> rewrite your patch with respective String.Compare call? You may count spaces
> at the end of each string and thus eliminate both trimming and case
> lowering.
Well, the ToLower thing was there before I started to do my
modifications, so why noone sugested this earlier :) ?
However I agree with You, so here is patch with String.Compare.
But I'm not going to do trimEnd myself. Counting spaces is meaningless
because if strings will have different length they will be different
anyway. And if I want to omit last spaces I'll have to check if they
are real last spaces and not just 3 spaces before next letter, so
Instead of nice trimEnd we'll have a loop inside comparison. In my
opinion this would take longer.

Best Regards
Jaroslaw Pawlak
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Comparison.patch
Type: text/x-patch
Size: 730 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20061204/6fb06f23/attachment.bin 

More information about the Mono-devel-list mailing list