I want a List<Container> where Container.Active == true and give only containerObject.Items > 2 . How can I filter the sublist this way?
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, if indicated.
source share