generated from deadlydog/Template.NewGitRepo
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tip: Add tip about defining array items on new lines without commas
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/PowerShellTips/2023-09-23-define-hardcoded-array-items-on-new-lines-without-commas.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$tip = [tiPS.PowerShellTip]::new() | ||
$tip.CreatedDate = [DateTime]::Parse('2023-09-23') | ||
$tip.Title = 'Define hardcoded array items on new lines without commas' | ||
$tip.TipText = @' | ||
When defining hardcoded arrays with many values in PowerShell, you can define each item on a new line without commas. This makes it easier to read and maintain the array items, and you don't have to worry about commas when adding or rearranging items. | ||
If you choose to define multiple array values on a single line, then you will need a comma between each item on the line. | ||
'@ | ||
$tip.Example = @' | ||
[string[]] $stringArray = @( | ||
'Notice that each item is on a new line without commas.' | ||
'This is much easier to read and maintain.' | ||
'And you can add comments to explain each item if needed.' # Like this. | ||
) | ||
[int[]] $intArray = @(1, 2, 3) | ||
'@ | ||
$tip.Urls = @( | ||
'https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.3#create-an-array' | ||
) | ||
$tip.MinPowerShellVersion = '0.0' | ||
$tip.Category = [tiPS.TipCategory]::Syntax # Community, Editor, Module, NativeCmdlet, Performance, Syntax, Terminal, or Other. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters