且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在linq查询where子句中使用string.compare

更新时间:2023-02-04 23:18:35

如果要检查Name是否包含搜索文本:

If you want to check to see if Name contains the search text:

AllApplications.Where(x => x.Name.ToUpperInvariant().Contains(txtSearch.Text.ToUpperInvariant()))).ToList();

如果要检查是否相等:

AllApplications.Where(x => string.Equals(x.Name, txtSearch.Text, StringComparison.OrdinalIgnoreCase)).ToList();

在原始查询中,您正在检查x.Name是否包含string.Compare的结果.我认为您不是要这样做,因为 string.Compare返回一个整数. string.Compare主要用于确定排序顺序.

In your original query, you were checking to see if x.Name contains the result of string.Compare. I assume you weren't trying to do this, since string.Compare returns an integer. string.Compare is used primarily for determining sort order.