I'm trying to get an a case-insensitive search to work in C#. Currently my code is:
private void txtSearch_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
if (!string.IsNullOrEmpty(txtSearch.Text))
{
var query = from o in App.Phonebook
where (o.PhoneNumber.Contains(txtSearch.Text) || o.Department.Contains(txtSearch.Text) || o.Name.Contains(txtSearch.Text) || o.Email.Contains(txtSearch.Text))
select o;
dataGridView.DataSource = query.ToList();
}
else
dataGridView.DataSource = phonebookBindingSource;
}
}
I have tried where (o.PhoneNumber.Contains(txtSearch.Text, StringComparison.InvariantCultureIgnoreCase)
, but I get the error "No overload for method 'Contains' takes 2 arguments." I don't want to do ToUpper()
and ToLower()
.
Any advice would be appreciated.