Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.