如何在 ListView c# 上显示 List 中所有大于 1 的数字
How to display all numbers greater than 1 from List on ListView c#
我想在 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 的数据 我只想在 lstLevel2
.
中显示 2,3 和 4
怎么做?
您可以使用 LINQ 查询执行此操作 - 您不需要 foreach
循环
lstLevel2.ItemsSource = listAlert.Where(x => x.SomeProperty > SomeValue).ToList();
您每次迭代都会覆盖 lstLevel2.ItemsSource。你想拆分它:
var list = new List<myItem>();
foreach (var item2 in listAlert)
{
if (item2.Data > 1)
{
list.Add(item2);
}
}
lstLevel2.ItemsSource = list;
我想在 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 的数据 我只想在 lstLevel2
.
怎么做?
您可以使用 LINQ 查询执行此操作 - 您不需要 foreach
循环
lstLevel2.ItemsSource = listAlert.Where(x => x.SomeProperty > SomeValue).ToList();
您每次迭代都会覆盖 lstLevel2.ItemsSource。你想拆分它:
var list = new List<myItem>();
foreach (var item2 in listAlert)
{
if (item2.Data > 1)
{
list.Add(item2);
}
}
lstLevel2.ItemsSource = list;