我想获得一组债券及其相关的到期时间,其中的到期时间.matamount > 200000。
编辑:(我只希望每个债券的到期集合包括到期时间> 200000)
这是一个 program.cs,它具有类 defs 和一个为查询填充测试数据的方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqToObjects
{
class Program
{
static void Main(string[] args)
{
Program.QueryCollection();
Console.ReadLine();
}
public static void QueryCollection()
{
List<Bond> bonds = Program.BuildCollections();
//how do I get a list of Bonds that have a maturity.MatAmount > 200,000?
}
public static List<Bond> BuildCollections()
{
List<Bond> bonds = new List<Bond>();
Bond bond;
for (int i = 1; i <= 10; i++)
{
bond = new Bond() {ID = i, Title = "Bond Title " + i.ToString() };
for (int j = 1; j <= 10; j++)
{
bond.Maturities.Add(new Maturity(){ID = j, BondID = i, MatDate = DateTime.Today.AddDays(j), MatAmount = 152000 * j});
}
bonds.Add(bond);
}
return bonds;
}
}
public class Bond
{
public int ID { get; set; }
public string Title { get; set; }
public List<Maturity> Maturities { get; set; }
public Bond()
{
Maturities = new List<Maturity>();
}
}
public class Maturity
{
public int ID { get; set; }
public int BondID { get; set; }
public DateTime MatDate { get; set; }
public int MatAmount { get; set; }
}
}