On Apr 12, 10:01*am, "Mr. Arnold" <MR. Arn...@Arnold.com> wrote:
> "shapper" <mdmo...@gmail.com> wrote in message
>
> news:d053553e-e527-4999-b08b-(E-Mail Removed)...
>
> > Hello,
>
> > I am filtering items from a list as follows:
>
> > IQueryable<Account> students = accounts.Where(a => a.Roles.Contains
> > (givenRole)).AsQueryable();
>
> > Roles is a List<String>
>
> > How can I check if Roles.Contains givenRole ignoring case?
> > Which means that if Roles contains "Admin" then any givenRole as
> > "ADMIN", "Admin", "AdMin" would pass.
>
> Most would use ToUpper() on the string to *be checked *and on the string
> doing the checking to make them all the same case so that the check can'tbe
> missed.
Except that using ToUpper() for case-insensitive comparison is a bad
idea, because it is not a lossless conversion (so strings that would
normally compare as not equal, even with case-insensitive comparison
enabled, may compare equal after ToUpper()). An example of a letter
that may trigger such behavior is "dotless I" in Turkish locale; see
http://en.wikipedia.org/wiki/Dotted_and_dotless_I
The correct way to perform case-insensitive comparisons, as Chris
demonstrated, is to use a comparison object with case-insensitive
semantics.