ListOfComment
是对象的List<Comment>
属性,最好的方法是:
ListOfComment = new List<Comment>
{
foreach(object a in b)
{
new Comment
{
Type = "",
Description = ""
}
}
}
答案 0 :(得分:0)
这在对象声明中是不可能的,你可以这样做
var comments = (from a in b
select new Comment
{
Type = "",
Description = "";
}).ToList();
您可以做的是(具有固定数量的条目)
var comments = new List<Comment>()
{
new Comment { Type= "", Description = "" },
new Comment { Type= "", Description = "" },
};