.NET or not .NET - ForEach

 .NET or not .NET - ForEach

Summary: Naive foreach loop has better performance than .NET foreach loop


.NET foreach loop: 
# Define an ArrayList in .NET
$dotnetfruits = [System.Collections.ArrayList]@("Apple", "Banana", "Cherry", "Date")
# Use foreach to iterate through each number in the ArrayList $dotnetfruits.foreach( { Write-Output $_ })

Naive foreach loop: 

# Define an array of strings

$fruits = @("Apple", "Banana", "Cherry", "Date")

# Using foreach to loop through each item in the array

$fruits.foreach({

    Write-Output $_

})

Comments

Popular posts from this blog

Emojie reference