对象Book具有类型的Author属性.Namestring
我想迭代所有的Authors并将它的Name字符串添加到用逗号分隔的一个字符串(不是数组),所以这个字符串应该在as
string authorNames = "Author One, Author two, Author three";
Run Code Online (Sandbox Code Playgroud)
string authorNames = string.Empty;
foreach(string item in book.Authors)
{
string fetch = item.Name;
??
}
Run Code Online (Sandbox Code Playgroud)
您可以将该string.Join功能与LINQ一起使用
string authorNames = string.Join(", ", book.Authors.Select(a => a.Name));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |