次のような Author オブジェクトのリストがある場合
List<Author> authors = new List<Author>{
new Author { Id = 1, Name = "John Freeman"};
new Author { Id = 1, Name = "Adam Kurtz"};
};
この例は実際には、作成者のリストを返す静的メソッドでラップされています。
私の他のオブジェクトの中にはAuthors
、 type のプロパティがありますList<Author>
。ここで、リストの 2 番目の作成者をプロパティに割り当てたいと思いAuthors
ます。
使えると思いましたAuthors = GetAuthors()[1].ToList()
; しかし、インデックス指定された著者の ToList() にアクセスできません。
明確にするために
private static List<Author> GetAuthors() return list of authors (example above).
var someObject = new SomeObject()
{
Authors = // select only Adam Kurtz author using index
// and assign to Authors property of type List<Author>
};