Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active November 12, 2019 16:11
Show Gist options
  • Save altrive/c9b39f5bc8dcc8791274 to your computer and use it in GitHub Desktop.
Save altrive/c9b39f5bc8dcc8791274 to your computer and use it in GitHub Desktop.
PowerShell v5 'using namespace' syntax test
#Require -Version 5.0
# using statement must appear before any other statements in a script.
# other using types(Assembly/Command/Module/Type) is not supported yet?
# [Enum]::GetNames('System.Management.Automation.Language.UsingStatementKind')
using namespace System.Diagnostics
using namespace System.Linq
function Main
{
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
#Using System.Diagnostics.Stopwatch
$sw = [Stopwatch]::StartNew()
sleep -Milliseconds 100
Write-Host ('Elapsed: {0} [ms]' -f $sw.ElapsedMilliseconds)
#Using System.Linq methods
[int[]] $array = 1..10
[Enumerable]::Where($array, [Func[[int], [bool]]]{ param ($p) $p % 2 -eq 0})
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment