using System;
using System.Collections.Generic;
using System.Linq;
namespace E
{
public class Data
{
public int Iv { get; set; }
public string Sv { get; set; }
}
public class Program
{
public static List<Data> Filter(List<Data> lst, int? iv, string sv)
{
IEnumerable<Data> res = lst;
if(iv != null)
{
res = res.Where(o => o.Iv == (int)iv);
}
if(sv != null)
{
res = res.Where(o => o.Sv == sv);
}
return res.ToList();
}
public static void Dump(List<Data> lst)
{
foreach(Data o in lst)
{
Console.WriteLine("{0} {1}", o.Iv, o.Sv);
}
}
public static void Test(List<Data> lst, int? iv, string sv)
{
Console.WriteLine("Filter: {0} {1}", iv, sv);
Dump(Filter(lst, iv, sv));
}
public static void Main(string[] args)
{
List<Data> lst = new List<Data> { new Data { Iv = 1, Sv = "A" }, new Data { Iv = 2, Sv = "BB" }, new Data { Iv = 3, Sv = "CCC" }, new Data { Iv = 3, Sv = "A" } };
Test(lst, 1, null);
Test(lst, 3, null);
Test(lst, null, "A");
Test(lst, null, "BB");
Test(lst, 3, "CCC");
Console.ReadKey();
}
}
}