title: How to calculate the total size of Blob storage containers in an storage account when using the new Azure.Storage.Blobs
body: <p>I have been using <code>Microsoft.Azure.Storage.Blob</code> for past year or two and this is how I was calculating the size of all containers:</p>
  <pre class="lang-cs prettyprint-override"><code>    var myStorageAccount = CloudStorageAccount.Parse(myConnectionString, string.Empty));
      var myClient = myStorageAccount.CreateCloudBlobClient();
  
      var myContainers = myClient.ListContainers();
  
      containerSize = myContainers .Sum(container =&gt; 
        container.ListBlobs(null, true).Cast&lt;CloudBlockBlob&gt;().Sum(blobItem =&gt; blobItem.Properties.Length));
  </code></pre>
  <p>However, that package is now deprecated and I have upgraded to use <code>Azure.Storage.Blobs</code>.</p>
  <p>I tried to use the ListContainers example from <a href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-containers-list?tabs=dotnet" rel="nofollow noreferrer">here</a>, but it looks like it needs C# 8:</p>
  <pre class="lang-cs prettyprint-override"><code>async static Task ListContainers(BlobServiceClient blobServiceClient, 
                                  string prefix, 
                                  int? segmentSize)
  {
      string continuationToken = string.Empty;
  
      try
      {
          do
          {
              // Call the listing operation and enumerate the result segment.
              // When the continuation token is empty, the last segment has been returned
              // and execution can exit the loop.
              var resultSegment = 
                  blobServiceClient.GetBlobContainersAsync(BlobContainerTraits.Metadata, prefix, default)
                  .AsPages(continuationToken, segmentSize);
              await foreach (Azure.Page&lt;BlobContainerItem&gt; containerPage in resultSegment)
              {
                  foreach (BlobContainerItem containerItem in containerPage.Values)
                  {
                      Console.WriteLine(&quot;Container name: {0}&quot;, containerItem.Name);
                  }
  
                  // Get the continuation token and loop until it is empty.
                  continuationToken = containerPage.ContinuationToken;
  
                  Console.WriteLine();
              }
  
          } while (continuationToken != string.Empty);
      }
      catch (RequestFailedException e)
      {
          Console.WriteLine(e.Message);
          Console.ReadLine();
          throw;
      }
  }
  </code></pre>
  <p>I am also not sure if looping through it is the right way to get the total size of the containers in the storage account.</p>
  <p>Can someone please help? Thank you.</p>