PowerShell converts values returned from function. How to avoid this?

前端 未结 4 1330
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 06:59

I am trying to return List< T> from PowerShell function, but get one of:

  1. null - for empty list
  2. System.Int32 - for list with one element
  3. Sy
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-13 07:24

    Yeah, powershell unrolls all collections. One solution is to return a collection containing the real collection, using the unary comma:

    function CreateClrList
    {
        $list = New-Object "System.Collections.Generic.List``1[System.Int32]"
        $list.Add(3)
        ,$list
    }
    

提交回复
热议问题