await foreach在 C#中找到的 VB.net 等價物是什么?
根據我發現 VB.net 的For Each不能使用Await運算子(等待運算子(Visual Basic))
例如,如何將此 C# 示例轉換為 VB.net(使用 Azure 存盤客戶端庫列出 blob)?
private static async Task ListBlobsFlatListing(BlobContainerClient blobContainerClient,
int? segmentSize)
{
try
{
// Call the listing operation and return pages of the specified size.
var resultSegment = blobContainerClient.GetBlobsAsync()
.AsPages(default, segmentSize);
// Enumerate the blobs returned for each page.
await foreach (Azure.Page<BlobItem> blobPage in resultSegment)
{
foreach (BlobItem blobItem in blobPage.Values)
{
Console.WriteLine("Blob name: {0}", blobItem.Name);
}
Console.WriteLine();
}
}
catch (RequestFailedException e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
throw;
}
}
uj5u.com熱心網友回復:
您可能需要撰寫 aFor Each變成的等效代碼。對于常規(同步)For Each回圈:
For Each item In Sequence
'Do whatever with item
Next
相當于:
Dim iterator = Sequence.GetEnumerator()
Do While iterator.MoveNext()
Dim item = iterator.Current
'Do whatever with item
End Do
我希望異步可列舉的轉換基本相同。
Dim iterator As IAsyncEnumerator(Of Object) 'Or appropriate type
Try
iterator = AsyncSequence.GetAsyncEnumerator()
Do While Await iterator.MoveNextAsync()
Dim item = iterator.Current
'Do whatever with item
End Do
Finally
Await iterator.DisposeAsync()
End Try
它不像你可以寫Await For Each(并且有適當的Using支持)那么干凈,但它并不算太遠。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/442645.html
上一篇:合并兩個大檔案
