I'm trying to execute the LINQ to objects query as follows:
var c1 = allCustomers
.Where(x => x.CompanyName.Replace("'", "").StartsWith(searchText))
.ToList();
This works fine as long as CompanyName is not null.
So, I thought this seems like the perfect place for the new null conditional operator! Just change to:
var c1 = allCustomers
.Where(x => x.CompanyName?.Replace("'", "").StartsWith(searchText))
.ToList();
and everything should work!
Instead, I get the error:
Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)
I'm not quite sure how to accomplish what I want here. How would I use the null conditional in this scenario?