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보다 작은 값을 인쇄해서는 안됩니다.
당신이 컨테이너의 길이가>이해야 의미합니까? – shahkalpesh
'i'는 무엇입니까? '?' ' –
'Items'의 각'int'가 2보다 작아야 함을 의미합니다. 2보다 작은 값은 모두 제거해야합니다. –