首页 > 解决方案 > 如何在ListView c#上显示列表中大于1的所有数字

问题描述

我想在 ListView 的列表中显示所有大于 1 的数字

foreach (var item2 in listAlert)
{
      int maxAlertt = item2.levelForecast;
      item2.levelForecast = Math.Max(maxAlertt, maxAlertt);
      lstLevel2.ItemsSource = listAlert;
}

listAlert有整数 1,2,3,4 的数据我只想显示 2,3 和 4 in lstLevel2.

怎么做 ?

标签: c#xamarin

解决方案


您可以使用 LINQ 查询来执行此操作 - 您不需要foreach循环

lstLevel2.ItemsSource = listAlert.Where(x => x.SomeProperty > SomeValue).ToList();

推荐阅读