gpt4 book ai didi

c# - 如何在 Linq 查询中比较字符串

转载 作者:太空狗 更新时间:2023-10-29 21:35:25 26 4
gpt4 key购买 nike

CompareTo 在这里对我不起作用。

我的 linq 查询是

var result = from c in customers 
where c.CustomerID.CompareTo(txtSerchId.Text) >= 0
select` c;

他们得到一个异常(exception)

//////异常///////////

System.ArgumentException was caught
Message=Value does not fall within the expected range.

我的代码是这样的

var result = 
from c in customers
where c.CustomerID.CompareTo(txtSerchId.Text) >= 0
select c;

if (result != null)
{
IEnumerator<Customer> resultEnum = result.GetEnumerator();
while (resultEnum.MoveNext())
{
Customer c = (Customer)resultEnum.Current;
addToDataSet(Guid.NewGuid().ToString(), c);
}
ShowResult();
}
else
{
MessageBox.Show("No Customer found within criteria");
}

异常(exception)是在这一行

IEnumerator<Customer> resultEnum = result.GetEnumerator();

最佳答案

试试这个:

var query = from c in customers where c.CustomerID.Equals(txtSerchId.Text) select c;

关于c# - 如何在 Linq 查询中比较字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10448451/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com