On Fri, 22 Aug 2008 04:16:09 -0700, shapper <md*****@gmail.comwrote:
[...]
How would I use String.Compare in this? I tried but I get an error:
Cannot implicitly convert type 'int' to 'bool'
That's because the CompareTo() method returns an int, not a bool.
If you're using the CompareTo() method, then I agree with Marc that you
should just use the == operator.
But your original question indicated you wanted a case-insensitive
comparison, in which case you'd use one of the String.Compare() overloads,
not String.CompareTo().
Resolving both mistakes at once, you could have:
bool check = (from t in database.Tags
where String.Compare(t.Name, Name,
StringComparison.InvariantCultureIgnoreCase)
== 0
select t).Any();
Note the comparison of the result of Compare() to the value 0, which is
what it returns when the two strings are equal.
This also assumes, of course, that you want the invariant culture. There
are other comparison options that ignore case for other types of
comparisons.
Pete