Skip to content

Instantly share code, notes, and snippets.

View caite's full-sized avatar

caite

  • New York, USA
  • 14:29 (UTC -05:00)
View GitHub Profile
@caite
caite / Types.md
Last active July 22, 2024 19:52 — forked from kevinblumenfeld/Types.md

Collection Type Guidance

Forked from a gist by @KevinBlumenfeld (Kevin Blumenfeld) originally credited to @MarkEKraus (Mark Kraus), author of Get-PowerShellBlog

A quick reference for choosing the right collection type in PowerShell. This guide includes best practices and examples for Arrays, Lists, HashTables, and more, demonstrating how to leverage .NET classes for enhanced functionality. PowerShell was originally designed to "expose the power of .NET in an admin-friendly way"[^dotNetPowerShell], providing direct integration with .NET classes and methods within Powershell.

When to use what

  • Use Arrays if you know the element types and have a fixed length and known-up-front collection size that absolutely, certifiably, categorically WILL NOT CHANGE.
  • Use ArrayList if you have an unknown collection size wit