문서로 건너뛰기
C#

페이지네이션

한 페이지, 모든 페이지, 또는 한 번에 한 항목씩.

한 페이지

page.cs
var page = await client.Threads.ListAsync(folder: "inbox", limit: 25); foreach (var thread in page){    Console.WriteLine(thread["id"]);} if (page.HasMore){    var next = await client.Threads.ListAsync(folder: "inbox", limit: 25, cursor: page.NextCursor);     Console.WriteLine(next.Count);}

ListAsync 메서드는 Items, HasMore, NextCursor가 있는 Page를 반환하며, foreach로 항목을 순회할 수 있습니다. 다음 페이지를 읽으려면 같은 필터와 함께 NextCursor를 cursor:로 다시 전달하세요.

모든 페이지

all.cs
var failed = await client.Emails.ListAllAsync(status: new[] { "failed" }); Console.WriteLine($"{failed.Count} messages failed");

ListAllAsync 메서드는 커서를 끝까지 따라가 모든 항목을 하나의 목록으로 반환합니다. 어느 페이지에서든 실패하면 호출 전체가 실패합니다.

한 번에 하나씩

iterate.cs
await foreach (var contact in client.Contacts.IterateAsync(limit: 100)){    if ((string?)contact["email"] == "[email protected]")    {        break;    }} await foreach (var entry in client.Emails.IterateEventsAsync("msg_3f9a1c07d2b84e6a9c5b1f20")){    Console.WriteLine(entry["type"]);}

IterateAsync 메서드는 IAsyncEnumerable<JsonObject>를 반환합니다. 루프가 도달했을 때만 다음 페이지를 요청하므로 break로 요청이 멈춥니다. 페이지로 나뉘는 모든 목록에는 순회하는 목록의 이름을 딴 세 가지가 모두 있습니다. 예를 들어 ListEventsAsync 옆에는 ListAllEventsAsync와 IterateEventsAsync가 있습니다.

순회는 이미 따라간 커서를 API가 다시 내놓으면 멈추므로, 끝없이 반복되는 일은 없습니다.