Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:07:44+00:00 2026-05-26T02:07:44+00:00

I have two code examples : var container = new CloudBlobContainer(address); var blobs =

  • 0

I have two code examples :

var container = new CloudBlobContainer("address");
var blobs = container.ListBlobs();
foreach (var blob in blobs)
{
    //Do somthing
}

and this :

var container = new CloudBlobContainer("address");
var blobs = container.ListBlobs().ToList();
foreach (var blob in blobs)
{
     //Do somthing
}

Will the second example give any advantage “transaction-wise” ?
How many transaction are made to the blob storage in each example ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:07:45+00:00Added an answer on May 26, 2026 at 2:07 am

    Edit: It appears this question is in reference to a blog post by Martin Ingvar Kofoed Jensen. The difference between this question and that question is the call to .Where(...).SingleOrDefault(). Because LINQ is lazy-evaluated, at the stage of Container.ListBlobs() it is still an IEnumerable and hasn’t yet called the REST API (no data has been retrieved). As soon as a result operation occurs (such as ToList() or SingleOrDefault()), the data is downloaded. Since a non-lazy operation is called on a lazy list inside the loop in the following code, it incurs a transaction for every loop iteration:

    foreach (string filePath in allFilesInStartFolder)
    {
        string fileHash = GetFileHashFromCache(filePath, lastSync);
    
        /* Checking for added files */
        var blob = blobs.Where(b => b.LocalPath == filePath).SingleOrDefault();
        // ^^ This is a non-lazy op on a lazy evalution, so it causes a REST call.
        ....
    }
    

    Regarding the question as it’s actually written: Both code snippets will incur a single transaction (up to 5,000 blobs). I tested both code snippets in LinqPad/Fiddler, and I only see a single API call to generate the list of blobs (replaced our storage name with {mystore}):

    https://{mystore}.blob.core.windows.net/
        {mystore}?restype=container&comp=list&delimiter=%2F&timeout=90
    

    According to the documentation for List Blobs REST API, up to 5,000 results can be returned in a single call. So if you want to list all blobs in the entire container, it will take at most (# blobs / 5000) transactions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this foreach loop: var includedElements = new HashSet<int>(); foreach(var e in elements)
I have the following two code blocks. Code block 1 var checkboxes = $(div.c1
I have these two pieces of code, wich one is more readable? foreach decimal
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
I have two code examples below. One works, but the second (using extend to
I have two code bases of an application. I need to copy all the
I have two pieces of C++ code running on 2 different cores. Both of
I have two controllers which share most of their code (but must be, nonetheless,
I have two identical byte arrays in the following segment of code: /// <summary>
I have two string variables which are both file paths. The code that worked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.