我試圖做到以下幾點,但不知道如何...使用.NET + Linq創建項目列表時,是否可以使用匿名方法?
var foo = new Foo
{
Id = MyRandom<int>(1, 100),
Name = MyRandom<string>(5,20),
MyPets = MyRandom<bool>() ?
new IList<Pet>
(petList =>
{
var x = MyRandom<int>(1, 4);
for (int i = 0; i < x; i++)
{
petList.Add(new Pet(MyRandom<string>(1,15));
}
}
: null
};
所以..這將創建寵物隨機列出。
任何想法?
你錯過了')' – harryovers
其實還有2人失蹤 – harryovers
是的,這只是pseduo代碼...得到跨越點.. –