0

我写了一个代码:

string strSearch = textBox1.Text;
XDocument xdoc;
List<string> lstItemsForAdd;
lstItemsForAdd = xdoc.Descendants("name")
                        .Where(item => item.Value.Contains(strSearch))
                        .Select(item => item.Value)
                        .Take(5)
                        .OrderBy(item => item)
                        .ToList();

现在这段代码对查找的大小写敏感......
我怎么能在不敏感大小写的情况下进行搜索,
但我不想将项目和 strSearch 转换为小写/大写字符
,所以我该怎么做做 ?

谢谢和亲切的问候。

4

1 回答 1

0

试试这个

string strSearch = textBox1.Text;
XDocument xdoc;
List<string> lstItemsForAdd;
lstItemsForAdd = xdoc.Descendants("name")
                        .Where(item => item.Value.IndexOf(strSearch. StringComparison.OrdinalIgnoreCase) >= 0)
                        .Select(item => item.Value)
                        .Take(5)
                        .OrderBy(item => item)
                        .ToList();
于 2013-02-17T05:56:09.450 回答