我在每个循环中使用IEnumerable,如下所示:

foreach (IListBlobItem blobItem in container.ListBlobs())
{
    if (blobItem is CloudBlobDirectory)
    {
        CloudBlobDirectory directory = (CloudBlobDirectory)blobItem;
        IEnumerable<IListBlobItem> blobs = directory.ListBlobs(true);
    }
}
await ProcessBlobs(blobs);


我想在此foreach循环之外使用blobs变量,但得到以下消息:blobs doesnot exist in the current context

我决定在foreach循环之外定义blobs

IEnumerable<IListBlobItem> blobs = new IEnumerable<IListBlobItem>;

foreach (IListBlobItem blobItem in container.ListBlobs())
{
    if (blobItem is CloudBlobDirectory)
    {
        //Console.WriteLine(blobItem.Uri);
        CloudBlobDirectory directory = (CloudBlobDirectory)blobItem;
        IEnumerable<IListBlobItem> blobs = directory.ListBlobs(true);
    }
}


但出现错误:can not create an instance of the abstract class or interface IEnumerable<IListBlobItem>

您知道如何解决此问题吗?

最佳答案

您可以将blobs声明为一个空集合,例如数组:

10-08 09:20