我要一个List<Container>
地方Container.Active == true
,只给我一个containerObject.Items > 2
。如何以这种方式过滤子列表?
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
internal class Container
{
public List<int> Items { get; set; }
public bool Active { get; set; }
public Container(bool active, params int[] items)
{
Items = items.ToList();
Active = active;
}
}
class Program
{
static void Main(string[] args)
{
var containers = new List<Container> {new Container(true,1, 2, 3), new Container(false, 1,2,3,4,5,6), new Container(true,1,2,5,6,7,8,9,10)};
var result = containers.Where(c => c.Active);
foreach (var container in result)
{
foreach (var item in container.Items)
{
Console.WriteLine(item);//I should not print any values less than two here
}
}
}
}
}
我不应该在注明的地方打印任何小于 2 的值。