0

Which code block is better?

            foreach (CloudBlockBlob b in allBlobs)
            {
                res.Add(b.Name);
            }

or

        foreach (var listBlobItem in allBlobs)
        {
            var b = (CloudBlockBlob) listBlobItem;
            res.Add(b.Name);
        }

I don't know why "foreach (var ...)" is more popular.

Üh Lieh
  • 35
  • 2
  • 6
  • 1
    `var` is replaced with the class in compilation, so both are equal. `var` is more popular because is way more simple to type. – Pedro Lima Apr 09 '20 at 12:05
  • The only way this question would kind of make sense is if it turns out `allBlobs` is `object[]`, `IEnumerable`, `IEnumerable` or some other moral equivalent (and is known to only actually contain `CloudBlockBlob` instances). Since you haven't shown us the definition of it though, impossible to say. – Damien_The_Unbeliever Apr 09 '20 at 12:46
  • allblob ist List – Üh Lieh Apr 17 '20 at 08:24

0 Answers0