对象ListOfComment的List<Comment>属性在哪里,最好的方法是:
ListOfComment = new List<Comment>
{
foreach(object a in b)
{
new Comment
{
Type = "",
Description = ""
}
}
}
Run Code Online (Sandbox Code Playgroud)
不是直接的,但你可以这样做:
ListOfComment = b.Select(a => new Comment {
Type = "",
Description = ""
}).ToList();
Run Code Online (Sandbox Code Playgroud)
要么:
ListOfComment = (from a in b
select new Comment {
Type = "",
Description = ""
}).ToList();
Run Code Online (Sandbox Code Playgroud)
要么:
ListOfComment = new List<Comment>(b.Select(a => new Comment {
Type = "",
Description = ""
}));
Run Code Online (Sandbox Code Playgroud)
要么:
ListOfComment = new List<Comment>(
from a in b
select new Comment {
Type = "",
Description = ""
});
Run Code Online (Sandbox Code Playgroud)