2

I was writing my code for searching in a database, so I wrote this code:

public IEnumerable<Company> SearchInCustomers(string Search)
{
    return Company.Where(w => 
         (w.CompanyName.ToLower().Contains(Search.ToLower())) ||
         (w.City.ToLower().Contains(Search.ToLower()))).OrderBy(w => w.Id);
}

I works fine and I thought it was good code. When I started to check my code with e.g. SonarCube (This is to review your code and spot bad code) it said that I was using the .ToLower() wrong. It showed me a message why and how to use this (if you want to see the message let me know) and it gave me a link.

It said I need to use .ToLowerInvariant(), but I had never heard of this.

So now I am wondering, is it really bad to use ToLower(), and should I use .ToLowerInvariant() or just it as I always did?

Edit:

The input is always in the same language, it is used in the country I live in and there is no way it can delete something. There is no "weird" input in the Search.

Max
  • 846
  • 1
  • 9
  • 26

0 Answers0