Undocumented changes to Powershell Scope handling v2/v3?

拈花ヽ惹草 提交于 2019-12-05 22:53:32

It is documented in the WMF 3 Release Notes in the section "CHANGES TO THE WINDOWS POWERSHELL LANGUAGE".

Script blocks executed as delegates run in their own scope

Add-Type @"
public class Invoker
{
    public static void Invoke(System.Action<int> func)
    {
        func(1);
    }
}
"@
$a = 0
[Invoker]::Invoke({$a = 1})
$a

Returns 1 in Windows PowerShell 2.0 
Returns 0 in Windows PowerShell 3.0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!