gpt4 book ai didi

c# - 为什么此动态列表比较失败?

转载 作者:太空宇宙 更新时间:2023-11-03 17:15:13 26 4
gpt4 key购买 nike

我有一个返回动态结果的搜索。所以如果没有找到结果,我会尝试只显示一个标签。我遇到的问题是我不知道如何计算结果,因为它是动态的并且不等于一种类型。

错误信息是:

Operator '!=' Cannot be applied ot operands of type System.Collections.Generic.List and int

 if (Page.IsValid)
{


string keyword = txtSearch.Text.Trim();
List<dynamic> results = SearchItems(keyword);
List<dynamic> Cresults = SearchContacts(keyword);



if(results != 0 || Cresults !=0)
{


//bind and return
LVI.DataSource = results;
LVI.DataBind();
// System.Threading.Thread.Sleep(500);

//Contact Bind return
LVC.DataSource = Cresults;
LVC.DataBind();
// System.Threading.Thread.Sleep(250);


lvAdmin.DataSource = results;
lvAdmin.DataBind();


LVCAdmin.DataSource = Cresults;
LVCAdmin.DataBind();
}
else{

NoResults.Visible = true;

}

最佳答案

不能只做:

if(results != 0 || Cresults !=0)
{

}

这样你就可以将实际的 List0 进行比较,这显然会失败。

只是做:

if(results.Count != 0 || Cresults.Count !=0)
{

}

或者:

if(results.Any() || Cresults.Any())
{

}

关于c# - 为什么此动态列表比较失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13781571/

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